awk pattern scanning and processing language
awk command may not be pre-installed on all Linux distributions. To install it use
# Debian/Ubuntu
sudo apt install awk
To use awk, just type awk '{command}' filename
Here I'm using movies.txt
as example
cat movies.txt
----
Title Release Year Budget Profit (Approx.) Studio Genre
Avatar 2009 $237 million ~$2.7 billion 20th Century Fox Sci-Fi / Action
Avengers: Endgame 2019 $356 million ~$2.2 billion Marvel Studios Superhero / Action
The Dark Knight 2008 $185 million ~$894 million Warner Bros. Superhero / Crime Thriller
Titanic 1997 $200 million ~$2.1 billion 20th Century Fox Romance / Drama
Jurassic World 2015 $150 million ~$1.3 billion Universal Pictures Sci-Fi / Adventure
Print all lines
Search Lines with a Keyword
Print Specific Columns
By default, awk uses space as separator, here I use tab as separator, so I need to set it as the separator.
Use of NR built-in variables to display line number
Use of NR built-in variables to display line 2 to 4
Use of NF built-in variables to display last field)
Print nonempty line with line number, first, second and last columns separated by -
Leave a comment if you have any questions.
===========
Please keep in touch
Portfolio
Linkedin
Github
Youtube
Top comments (0)