Awk One Liner

1) File Spacing

-> double space a file
 awk '1;{print ""}'
 awk 'BEGIN{ORS="\n\n"};1'
-> double space a file which already has blank lines in it. Output file should contain no more than one blank line between lines of text. NOTE: On Unix systems, DOS lines which have only CRLF (\r\n) are often treated as non-blank, and thus 'NF' alone will return TRUE.
 awk 'NF{print $0 "\n"}'
-> triple space a file
 awk '1;{print "\n"}'
2) NUMBERING AND CALCULATIONS

-> precede each line by its line number FOR THAT FILE (left alignment). -> Using a tab (\t) instead of space will preserve margins.
 awk '{print FNR "\t" $0}' files*
-> precede each line by its line number FOR ALL FILES TOGETHER, with tab.
 awk '{print NR "\t" $0}' files*
-> number each line of a file (number on left, right-aligned) -> Double the percent signs if typing from the DOS command prompt.
 awk '{printf("%5d : %s\n", NR,$0)}' 
-> number each line of file, but only print numbers if line is not blank -> Remember caveats about Unix treatment of \r (mentioned above)
 awk 'NF{$0=++a " :" $0};1'
 awk '{print (NF? ++a " :" :"") $0}'
-> count lines (emulates "wc -l")
 awk 'END{print NR}'
-> print the sums of the fields of every line
 awk '{s=0; for (i=1; i<=NF; i++) s=s+$i; print s}'
-> add all fields in all lines and print the sum
 awk '{for (i=1; i<=NF; i++) s=s+$i}; END{print s}'
-> print every line after replacing each field with its absolute value
 awk '{for (i=1; i<=NF; i++) if ($i < i =" -$i;">
 awk '{for (i=1; i<=NF; i++) $i = ($i <>
-> print the total number of fields ("words") in all lines
 awk '{ total = total + NF }; END {print total}' file
-> print the total number of lines that contain "Beth"
 awk '/Beth/{n++}; END {print n+0}' file
-> print the largest first field and the line that contains it -> Intended for finding the longest string in field #1