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.
awk '{for(i=3;i<=NF;++i)print $i}' be more compact. :)
2009-10-21 16:58:31
Thanks, lh3. I was just copying and pasting for the gawk manual. :)
Jonathan Feinberg
2009-10-21 17:07:13
From. From. From.
Jonathan Feinberg
2009-10-21 17:08:14
The key point here is the existence and meaning of NF.
dmckee
2009-10-21 21:13:17
+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
2009-10-21 16:46:58
I'd avoid regex. It's probably slower and easier to accidentally mess up.
Jefromi
2009-10-21 17:13:00
+2
A:
...or a simpler solution: cut -f 3- INPUTFILE
just add the right delimiter (-d) and you got the same effect.
Marcin
2009-10-21 17:11:26
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
2010-01-13 21:11:48
+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
2009-10-21 18:05:59
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
2009-10-24 02:33:36