for screening, filtering, and extracting rows and columns of text tables
print column 3 and 4 of file 'table.txt'
file input/output: read from file 'table.txt' and write to file 'newTable.txt'
to use in a pipe
print only columns 3 and 4 when column 3 contains "gene123"
print complete line when column 3 contains "gene123"
print complete line when column 3 contains NOT "NA" (alternatively use grep, see below)
awk '$3!="NA"' table.txt
print lines in which the ratio between columns 4 and 5 is smaller than 0.4
print columns separated by tab
change output field separator (OFS) to tabular "\t", instead of using space by default
additionally, fix also input field separator (-F) to tabular "\t", in case of empty fields
switch column 3 and 4
switch only in lines where field 3 is larger than field 4
print columns in any specific order
For extracting columns from text files, see also: cut
combine multiple conditions
AND operator: &&
OR operator: ||
Count number of columns in each line
# file separator 'FS' can be replaced by any column separator FS="\t" or FS="|" or FS=":" ...
Sum and mean average of numbers in column 2
For getting word frequencies, see also: uniq -c
# remove all empty lines (d - delete)
# remove all lines containing 'NA'
# remove all lines that contain multiple strings from the unwanted word list file
-w search for full word, not substring
-F read pattern as plain text, not interpreting special characters as regular expressions
-f read pattern from file
-v keep non-matching lines (remove lines that contain the searched word)