Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cwjcc!tut.cis.ohio-state.edu!att!chinet!john From: john@chinet.chi.il.us (John Mundt) Newsgroups: comp.unix.questions Subject: Re: extracting "rest of line" in AWK Message-ID: <9363@chinet.chi.il.us> Date: 25 Aug 89 18:45:19 GMT References: <3368@blake.acs.washington.edu> Reply-To: john@chinet.chi.il.us (John Mundt) Distribution: na Organization: Chinet - Public Access Unix Lines: 47 In article <3368@blake.acs.washington.edu> mbader@cac.washington.edu (Mark Bader) writes: >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 I understand this correctly, and if the quotes come around the heading all the time, you can use the split() function to break the line up in to three substriings, namely 1) <%% Heading > 2) 3) <> by using split as in split($0,chop,"\""); # I don't know if an escaped # quote will work or if you'd have to # change FS to it You could then print the thing, with the quotes, by doing printf("\"%s\"\n",chop[2]); If there are no quotes, you could still split it at every space and print each separate array piece until you ran out of them: (I assume that there are a variable number of words in the heading) split($0,chop); i = 3; while (chop[i] != "") printf("%s ",chop[i++]); printf("\n"); for ( i = 0;; i++) # zero out the array at the end chop[i] = ""; # after each use The only problem here would be to allow for several spaces in a row as in "This is a heading". I haven't tested split to see if it would skip these null fields or not. -- --------------------- John Mundt Teachers' Aide, Inc. P.O. Box 1666 Highland Park, IL john@chinet.chi.il.us (312) 998-5007 (Day voice) || -432-8860 (Answer Mach) && -432-5386 Modem