extracting "rest of line" in AWK
Jaap Akkerhuis
jaap+ at andrew.cmu.edu
Sat Aug 26 03:56:09 AEST 1989
> Excerpts from netnews.comp.unix.questions: 25-Aug-89 extracting "rest of
> line" i.. Mark Bader at cac.washingto (670)
> Does anyone know of a way to extract the "rest of the line" in awk..
> e.g. I have a line that looks like
> %% Heading "This is a Graph Heading"
> and I want to do a {print $3} to get the "This is a Graph Heading" part,
> but this obviously dosen't work. Is there a way to do this?
> If there were a shift command, then I could shift off the first 2 fields,
but is there a way to simulate this?
Allthough it is a bit ugly, you can empty the first two fields, so
something like:
{ $1="\0"; $2="\0"; print $0 }
Of course, now you will have two spaces in front of the line printed. If
you want to get rid of this you need a for loop in the style of "{ for(i
= 3; i < NF; i++) printf("%s ", $i); print ""}" or just filter them out
with an "awk '{ $1=""; $2=""; print $0 }' | sed 's/^ //'".
There are tons of other ways to do this as well.
jaap
More information about the Comp.unix.questions
mailing list