[Linux] awk, sed command

The number of test statistics file
cat filename | awk '{for ( i = 1; i <= NF; ++ i) if ($ i == "test") ++ sum} END {print sum}'
statistics a list of all the elements of occurrences
CAT filename | awk '{A [$. 1] ++} the END {for (I in A) {Print I, A [I]}}'
CAT filename | awk '{Print $. 1}' | the uniq - c

Remove to a beginning
sed -i '/ ^ a / d ' filename
replace all of a B
Sed -i 'S / a / B / G' filename
first row to fifth row output
sed -n '1,5p' filename
first row to the fifth row is replaced cccc cc
Sed -i '1,5s / cccc / cc / G' filename
rows containing bb2 cc and the middle row containing gg7 is replaced cccc (regular)
Sed -i '/ bb2 /, / gg7 / s / cc / cccc / g 'filename

Guess you like

Origin www.cnblogs.com/20190119-tl/p/11532126.html