extracting "rest of line" in AWK

David Goodenough dg at lakart.UUCP
Sun Aug 27 23:28:34 AEST 1989


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.

	{ for (i = 3; i <= NF; i++) {
			if (i == NF)
			 {
			    a = "\n";
			 }
			else
			 {
			    a = " ";
			 }
			printf "%s%s", $i, a; } }

Or somesuch. I'm making the above up as I type here, so I can't guarantee it,
but it should provide a starting point. An alternative approah is to use
length($1) and length($2) and substr(), but again that assumes a lot about
the input record.

Enough rambling, I'm not really an awk guru. We now return you to your
regular news articles.
-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com			  +---+



More information about the Comp.unix.questions mailing list