Awk-f ': ' {print $3,$4} ' 1.txt
Awk-f ': ' ofs= ': ' {print $3,$4} ' 1.txt
awk '/root|user/' 1.txt matches root or user
awk '/(OO) +/' 1.txt one or more oo
Awk-f ': ' $1~/r*o/{print $} ' 1.txt the first paragraph to match r*o, and only print the third paragraph
Awk-f ': ' $1~/root/{print $1,$3}; $1~/user/{print $1,$3} ' 1.txt matches separately
Awk-f ': ' $1~/root|nobody/{print $1,$3} ' 1.txt or
Conditional operator
Awk-f ': ' $1== ' root ' {print '} ' 1.txt
Awk-f ': ' $1== ' root ' | | $7~/nologin/' 1.txt The first paragraph is root or 7th paragraph is nologin
You can use!~ to indicate that the mismatch $7!~/nologin/the 7th segment does not match the login
awk position variable nr line
Awk-f ': ' nr<10 {print $5,$1,$7} ' 1.txt printing the first 9 lines
Awk-f ': ' {if (nr==10) print $1,$3,$4} ' 1.txt
Awk-f ': ' ofs= "%" {if (nr==10) print $1,$2} ' passwd print paragraph 122 of line tenth
Awk-f ': ' {print NF} ' 1.txt prints a few paragraphs in each line
Awk-f ': ' ofs= ' # # ' {if (nf==7) print $1,$7} ' passwd printing is the first and seventh paragraphs in each row of paragraph 7
Awk-f ': ' {print $NR print $NF} ' 1.txt
Awk-f ': ' ofs= ': ' {$7=$3+$4 print $ '} 1.txt
Awk-f ': ' {(sum=sum+$3)}; END {print sum} ' 1.txt loop (note the position of the single quotation mark)
Awk-f: '/^root:/{ofs= ' # # ';p rint $1,$3,$6;} ' passwd
This article is from the "Share,open source" blog, so be sure to keep this source http://liqilong2010.blog.51cto.com/3029053/1857120
Shell Practice-awk Command