Awk is a great language for useful one-line programs. Below are a number of useful awk scripts that can be coded in a single line.
# Emit every line that is not blank awk 'NF > 0 {print}' file.txt # Emit the number of lines in a file awk '{num_lines++} END{print num_lines}' file.txt # or (another number of lines example) awk 'END { print NR }' file.txt # Emit the first 10 lines of a file (like head) awk 'NR < 11 { print# Emit every line that is not blank awk 'NF > 0 {print}' file.txt # Emit the number of lines in a file awk '{num_lines++} END{print num_lines}' file.txt # or (another number of lines example) awk 'END { print NR }' file.txt # Emit the first 10 lines of a file (like head) awk 'NR < 11 { print $0 }' file.txt # Print each line, preceded by its line number awk '{print NR, $0}' missiles.txt # Count the number of lines that contain 'PATTERN' awk '/PATTERN/{num++} END{ print num }' file.txt}' file.txt # Print each line, preceded by its line number awk '{print NR,# Emit every line that is not blank awk 'NF > 0 {print}' file.txt # Emit the number of lines in a file awk '{num_lines++} END{print num_lines}' file.txt # or (another number of lines example) awk 'END { print NR }' file.txt # Emit the first 10 lines of a file (like head) awk 'NR < 11 { print $0 }' file.txt # Print each line, preceded by its line number awk '{print NR, $0}' missiles.txt # Count the number of lines that contain 'PATTERN' awk '/PATTERN/{num++} END{ print num }' file.txt}' missiles.txt # Count the number of lines that contain 'PATTERN' awk '/PATTERN/{num++} END{ print num }' file.txt