extracting "rest of line" in AWK

Jon H. LaBadie jon at jonlab.UUCP
Tue Sep 5 14:54:04 AEST 1989


In article <671 at lakart.UUCP>, dg at lakart.UUCP (David Goodenough) writes:
> mbader at cac.washington.edu (Mark Bader) asks:
> > 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?  
> 
> It's fairly grotesque, a lot of work, but the following should work,
> assuming you're not to worried about spaces.
> 

SOLUTION DELETED

New awk added a substitute function that can get rid of unwanted fields
whild preserving the spacing in the rest of the record.  For example,

	sub($1, "", $0)

should get rid of field on while leaving the remainder of the record
intact (including spacing).  Repeating the above command should get
rid of field one and two.  An alternative, in one statement is

	sub($1 "[ 	]*" $2 "[ 	]*", "", $0)

where each set of square brackets contains a tab and a space.

Remember to preserve $1 and $2 if the logic of the program requires
them at a later point in the code.

Jon LaBadie
-- 
Jon LaBadie
{att, princeton, bcr}!jonlab!jon
{att, attmail, bcr}!auxnj!jon



More information about the Comp.unix.questions mailing list