Awk tutorial: three ways of awk execution

Linux awk command execution ways:

1. Command line execution

➜ awk -F" " '{print $2}' test.txt
linux awk command line exec

Detailed introduction of syntax, see 《Linux awk

2. Shell script file execution

➜ vim test1.awk

#!/usr/bin/awk -f
        print $2

➜ ./test1.awk  test.txt
linux awk shell script exec


The first line of #!/usr/bin/awk is the awk command location.

use : ➜ which awk /usr/bin/awk

3. Awk script file execution

➜ vim test.awk
{print $2}

➜  awk -f test.awk test.txt
linux awk script file exec

Related post

awk command tutorial in linux/unix with examples and use cases
Awk tutorial: awk merge files base on the keyword
AWK tutorial: awk custom function and awk example
Awk tutorial: find and kill process use awk
Awk tutorial: awk -F and awk BEGIN{ FS … }
Awk tutorial: awk regex example
Awk tutorial: awk loop example: awk for and while
awk if else, if else if else and awk if else nested example
Awk tutorial: awk NR FNR difference
Awk tutorial: awk sort uniq
Awk tutorial: split on character awk or cut
Awk tutorial: awk newline character
How to print tree directory structure in linux/unix
Linux shell batch move files, delete spaces, rename files
Linux common commands tutorial and use examples
Linux system directory structure
Docker common commands list with examples

Add a Comment

Your email address will not be published. Required fields are marked *