The awk
command in Linux is a text processing tool that is used for working with structured data, such as data in tabular format. It is a versatile command that can be used for many different text processing tasks, such as printing selected columns from a file, performing calculations on fields of data, and more. The awk
command is named after the three developers of the tool: Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan.
Here are some examples of using the awk
command:
- To print the second field of a file called
example.txt
that is delimited by whitespace, you would use the following command:
awk '{ print $2 }' example.txt
- To print the second and the third fields of the same file that is delimited by ‘:’ (colon), you would use the following command:
awk -F: '{ print $2 " " $3 }' example.txt
- To print the number of lines that contain the word “error” in a file called
logfile.txt
, you would use the following command:
awk '/error/ { count++ } END { print count }' logfile.txt
- To print the average of the values in the third column of a file called
data.txt
, you would use the following command:
awk '{ sum += $3 } END { print sum/NR }' data.txt
- To print the first column of each line that starts with the letter “a” in a file called
file.txt
, you would use the following command:
awk '/^a/ { print $1 }' file.txt
awk
also supports complex program logic using if-else
and loops.
The awk
command is quite powerful and can be used in many different ways depending on your needs. The examples I provided are just a small sample of the things you can do with the awk
command.
Please let me know if you have any questions or need further clarification on how the awk
command works.
Other Linux Commands
- admin Command
- alias Command
- apt Command
- ar Command
- asa Command
- at Command
- awk Command
- basename Command
- bash Command
- batch Command
- bc Command
- bg Command
- break Command
- c99 Command
- cal Command
- cat Command
- cd Command
- cflow Command
- chgrp Command
- chmod Command
- chown Command
- chroot Command
- cksum Command
- clear Command
- cmp Command
- comm Command
- command Command
- compress Command
- continue Command
- cp Command
- crontab Command
- csplit Command
- ctags Command
- cut Command
- cxref Command
- datamash Command
- date Command
- dc Command
- dd Command
- delta Command
- df Command
- diff Command
- dir Command
- dirname Command
- dot Command
- du Command
- echo Command
- ed Command
- env Command
- eval Command
- ex Command
- exec Command
- exit Command
- expand Command
- export Command
- expr Command
- false Command
- fc Command
- fg Command
- file Command
- find Command
- flex Command
- fold Command
- fort77 Command
- fortune Command
- ftp Command
- fuser Command
- gawk Command
- gencat Command
- get Command
- getconf Command
- getopts Command
- grep Command
- groupadd Command
- groupdel Command
- groups Command
- hash Command
- head Command
- history Command
- hostname Command
- htop Command
- iconv Command
- id Command
- iostat Command
- ipcrm Command
- ipcs Command
- jobs Command
- join Command
- kill Command
- last Command
- less Command
- lex Command
- link Command
- ln Command
- locale Command
- localedef Command
- locate Command
- logger Command
- login Command
- logname Command
- logout Command
- lp Command
- ls Command
- m4 Command
- mailx Command
- make Command
- man Command
- mesg Command
- mkdir Command
- mkfifo Command
- mktemp Command
- more Command
- mount Command
- mtail Command
- mv Command
- nano Command
- netstat Command
- newgrp Command
- nice Command
- nl Command
- nm Command
- nohup Command
- od Command
- parallel Command
- passwd Command
- paste Command
- patch Command
- pathchk Command
- pax Command
- pgrep Command
- ping Command
- pkill Command
- pr Command
- print Command
- printf Command
- prs Command
- ps Command
- pstree Command
- pwd Command
- qalter Command
- qdel Command
- qhold Command
- qmove Command
- qmsg Command
- qrerun Command
- qrls Command
- qselect Command
- qsig Command
- qstat Command
- qsub Command
- read Command
- readlink Command
- readonly Command
- renice Command
- return Command
- rm Command
- rmdel Command
- rmdir Command
- rsync Command
- sact Command
- sar Command
- sccs Command
- sed Command
- seq Command
- set Command
- sh Command
- shift Command
- shopt Command
- sleep Command
- sort Command
- split Command
- ss Command
- stress Command
- strings Command
- strip Command
- stty Command
- suspend Command
- tabs Command
- tail Command
- talk Command
- tee Command
- test Command
- time Command
- times Command
- top Command
- touch Command
- tput Command
- tr Command
- traceroute Command
- trap Command
- true Command
- ts Command
- tsort Command
- tty Command
- type Command
- ulimit Command
- umask Command
- umount Command
- unalias Command
- uname Command
- uncompress Command
- unexpand Command
- unget Command
- uniq Command
- unlink Command
- unset Command
- unzip Command
- uptime Command
- useradd Command
- userdel Command
- uucp Command
- uudecode Command
- uuencode Command
- uustat Command
- uux Command
- val Command
- vi Command
- w Command
- wait Command
- wc Command
- what Command
- whereis Command
- which Command
- who Command
- write Command
- xargs Command
- yacc Command
- zcat Command
- zip Command
- Linux Commands and Examples
0 Comments