linux: awk usage summary

awk learning
created empty awk_test.txt Touch
awk '{} Print' awk_test.txt
awk '{}. 1 Print $' awk_test.txt
awk '{$. 1 Print "\ T" $ 2}' awk_test.txt
awk '{Print NR " \ T "$. 1" \ T "$ 2" \ T "} $. 3 'awk_test.txt
awk' {Print NR, $ 0} 'awk_test.txt
awk' {$ $ 1986print == 0}. 3 'awk_test.txt
awk' {$. 1 == "Gold" Print $ 0} 'awk_test.txt
awk' {Print of NF, $ 0} 'awk_test.txt
awk' {Print. 7 of NF == NR, $ 0} 'awk_test.txt
awk' the BEGIN the FS = { ","} {Print $ 1, $ 2} 'input separator
awk' BEGIN {OFS = ", "} {print $ 1, $ 2} ' output separator
awk' BEGIN {FS = ", "; OFS = ","} {print $ 1, $ 2} '
You can print two files
awk'{print NR ,FILENAME,$0}' a.txt b.txt

awk '{$ 3 = "xxxx"; print $ 0}' a.txt third column replacement by xxx

awk '{print $ NF}' a.txt a final print
awk '{a = 1; b = 2; print a + b}'
regular expression
awk '/ ABC / Print $ {0}' a.txt
awk '/ A \ .c / Print $ {0} 'a.txt
awk' / A // C / Print $ {0} 'a.txt
^ $ beginning and end
[AZ]
* + 0 or more occurrences of one or more
? 0 or 1
{3} occurs three times
{3,4} occur three or four times
()
awk '/ (ab &) 3 {C} / {0} Print $' a.txt

Guess you like

Origin www.cnblogs.com/logol/p/11862531.html