AWK One Liners

# Print field number 4, 5, and all the rest
awk '{$1=$2=$3=""; print $0}' 

# Split every line of the file x.txt at each comma
awk -F, '{for (i=1; i<=NF; i++) print $i}' x.txt

# Print only filenames of logfiles which contain a line matching /xyz/.
awk '/xyz/{print FILENAME; nextfile}' *.log

Trim leading and ending whitespace of field number two and print result. Attention, gsub does its work in place and returns the number of replacements. So you cannot use print gsub(/^[ \t]+|[ \t]+$/, "", $2);

awk '{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}'

Put apostrophes around a field. I found no way to do this with awk in the shell. Instead, I came up with this:

awk '{printf("+%s+\n", $i)}' | tr + "'"

Split comma separated lines of texts from file 1.txt, trim leading and ending whitespace of fields and convert all into the middle part of an SQL-statement with LIKE.

awk -F, '{for (i=1; i <= NF; ++i) { gsub(/^[ \t]+|[ \t]+$/, "", $i); printf("+%s%s+ or artikel like \n", $i, "%")} }' 1.txt  | tr + "'"

Print filename, line number and line matching xyz in each file (instead of a total line nr). Didn’t find quickly a solution in awk, using find -exec:

find . -type f -exec  awk '/xyz/{print FILENAME, NR, $0}' {} \; 
# Use multiple characters -+. and space as field separators.   
awk -F'[-+ .]'     # The delimiter is a regular expression! 

# Print lines from match1 to match2.
awk '/match1/,/match2/'

# ... lines from mat1 to mat2, ignoring case in match expression.
awk 'tolower($0)~"mat1",tolower($0)~"mat2"'  # OR 
awk 'BEGIN{IGNORECASE=1}/mat1,mat2/'         # Only with gawk! 

More AWK help

Perment’s AWK One Liners
Tuxgraphics’ AWK One Liners
AWK One Liners Explained
Gnu AWK User’s Guide