On shell, I pipe to awk when I need a particular column.
This prints column 9, for example:
... | awk \'{print $9}\'
How can I tell
sed -re 's,\s+, ,g' | cut -d ' ' -f 9-
Instead of dealing with variable width whitespace, replace all whitespace as single space. Then use simple cut
with the fields of interest.
It doesn't use awk so isn't germane but seemed appropriate given the other answers/comments.
awk '{print substr($0, index($0,$9))}'
Edit: Note, this doesn't work if any field before the ninth contains the same value as the ninth.
To display the first 3 fields and print the remaining fields you can use:
awk '{s = ""; for (i=4; i<= NF; i++) s= s $i : "; print $1 $2 $3 s}' filename
where $1 $2 $3 are the first 3 fields.
function print_fields(field_num1, field_num2){
input_line = $0
j = 1;
for (i=field_num1; i <= field_num2; i++){
$(j++) = $(i);
}
NF = field_num2 - field_num1 + 1;
print $0
$0 = input_line
}
awk '{ s = ""; for (i = 9; i <= NF; i++) s = s $i " "; print s }'
Generally perl replaces awk/sed/grep et. al., and is much more portable (as well as just being a better penknife).
perl -lane 'print "@F[8..$#F]"'
Timtowtdi applies of course.