Linux: awk
show nth column
# print the 7th column. (columns are separated by spaces by default.) cat myFile | awk '{print $7}'
For delimiter other than space, for example tab, use -F
option. Example:
# print 12th atd 7th column, Tab is the separator cat myFile | awk -F\t '{print $12 , $7}'
Alternative solution is to use the cut
utility, but it does not accept regex as delimeters. So, if you have column separated by different number of spaces, “cut” cannot do it.
sum up 2nd column
awk '{sum += $2} END {print sum}' filename
- Sum the 2nd column in a file.