cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Etc


Reference














.

os:linux:command:awk.html



Linux Commands Cheat Sheet

awk - How to use awk Command in Linux

man awk

NAME
       gawk - pattern scanning and processing language


Example

Operation Command
1st column awk '{ print $1 }' FILE
1,4 column awk '{ print $1 $4 }' FILE
2 column , “:” is filed sepalater awk -F: '{ print $2 }'

#echo "1 2 3 4 5" | awk '{ print $1,$3 }'
1 3
#

#echo "1 2 3 4 5" | awk '{ print $1 $3 }'
13
#

#echo "1 2 3 4 5" | awk '{ print $1 "," $3 }'
1,3
#

#echo "1 2 3 4 5" | awk '{ print $NF }'
5
#

#echo "1 2 3 4 5 6 7 8" | awk '{ {for(i=2;i<NF;i++)printf("%s ",$i) }print($NF) }'
2 3 4 5 6 7 8
#

#echo "1 2 3 4 5" | awk '{print $1 "        " $4 }'
1        4
#

#echo "1 2 3 4 5" | awk '{print $1 "\t" $4 }'
1       4
#

#echo "1 2 : 3 4 : 5" | awk -F: '{ print $2 }'
 3 4
#

TIPS

NULL

awk -F, '{ if($9=NULL) print $6 "," $9 }' 

awk -F, '{ if($9!=NULL) print $6 "," $9 }' 


cat httpd.log | awk -F'\t' '$14=="JP" {print $3}' 
vmstat 1 86400 | awk '{print strftime("%Y/%m/%d %H:%M:%S"), $0} { system(":") }' >> vmstat.`date +%Y%m%d`





Linux Commands Cheat Sheet




os/linux/command/awk.html.txt · Last modified: 2017/05/14 by admin

Page Tools