tags:

views:

808

answers:

5

I'm trying to parse out a DbgView log file the first three columns of which I'm not interested in. I can't seem to find an example that prints from column 3 onwards until the end of the line. Note that each line has variable number of columns.

+2  A: 
awk '{for(i=3;i<=NF;++i)print $i}'
Jonathan Feinberg
awk '{for(i=3;i<=NF;++i)print $i}' be more compact. :)
Thanks, lh3. I was just copying and pasting for the gawk manual. :)
Jonathan Feinberg
From. From. From.
Jonathan Feinberg
The key point here is the existence and meaning of NF.
dmckee
+1  A: 

Well, you can easily accomplish the same effect using a regular expression. Assuming the separator is a space, it would look like:

awk '{ sub(/[^ ]+ +[^ ]+ +/, ""); print }'
Eddie Sullivan
I'd avoid regex. It's probably slower and easier to accidentally mess up.
Jefromi
+2  A: 

...or a simpler solution: cut -f 3- INPUTFILE just add the right delimiter (-d) and you got the same effect.

Marcin
Note that this only works if the delimiter is exactly the same between all columns... For example, you can't use cut with a delimiter like \d+. (That I know of.)
Zach Wily
+1  A: 

Jonathan Feinberg's answer prints each field on a separate line. You could use printf to rebuild the record for output on the same line, but you can also just move the fields a jump to the left.

awk '{for (i=1; i<=NF-3; i++) $i = $(i+3); NF-=3; print}' logfile
Dennis Williamson
A: 
awk '{$1=$2=$3=""}1' file

NB: this method will leave "blanks" in 1,2,3 fields but not a problem if you just want to look at output.

ghostdog74