Several Frequently Used Commands

sed '/^\s*$/d' a.txt # delete ALL blank lines
sed '/./,$!d' a.txt # delete all leading blank lines at top of file

 

sed '=' a.txt | sed 'N;s/\n/\t/' # cat -n a.txt

sed '/./=' a.txt | sed '/./N; s/\n/\t/' # number each not blank line of file

 

sed '1!G;h;$!d' a.txt # reverse order of lines

sed '/./,$!d' a.txt # delete all leading blank lines at top of file

sed '$!N; /^\(.*\)\n\1$/!P; D' a.txt # delete duplicate, consecutive lines

 

gawk '$1~/[0-9].*/{total += $2} END{print total}' a.txt
gawk 'BEGIN {"cat c.txt | wc -l"|getline n} n>10 {print}' a.txt

ls | gawk -F. '{system("mv " $0 " " sprintf("%03d", $1) "." $2)}

 

你可能感兴趣的:(linux,awk,sed)