Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use awk to get multiple lines

Status
Not open for further replies.

jasonb817

Technical User
Nov 1, 2005
3
US
I need to use awk to get multiple lines within a file with the record seperator being a double quote. I am trying the following:
cat dbpccq.sh.old |awk 'BEGIN{ FS = "\n"; RS = "\"" }
/VOLUMETABLE="/ {print $0}'

I am trying to pull the information from a file like the following example:
"line1"
line2
VOLUMETABLE="
line3
line4
line5
"
line6

I want to get the information from VOLUEMTABLE to the quote after line5.

Any idea how because my way doesn't work.




 
Hi

Sorry, this is an ugly off-topic idea. But why not run the file as a shell script, then you will have the value in the VOLUMETABLE environment variable ? Of course, there will be errors too, and if the file could have lines begining with "rm", forget my idea.

Feherke.
 
It's not an awk solution, but this tr/sed solution works if you're only looking for one "VOLUMETABLE"

Code:
<inputfile tr '\n' ' '|sed 's/^.*VOLUMETABLE *= *"/VOLUMETABLE="/; s/ " .*$/ "/'|tr ' ' '\n'
VOLUMETABLE="
line3
line4
line5
"

or to get the value of VOLUMETABLE with newlines converted to spaces:

Code:
<inputfile tr '\n' ' '|sed 's/^.*VOLUMETABLE *= *"/VOLUMETABLE="/; s/ " .*$/ "/'
VOLUMETABLE=" line3 line4 line5 "

the idea is to first convert newlines to space
then delete all text from beginning to VOLUMETABLE=
then delete all text from end quote to end of line
then optionally convert spaces back to newlines

If spaces occur already in your lines of interest, you can use another character to convert newlines into (and back from), but then adjust the sed substitutions accordingly.


HTH,

p5wizard
 
Try...[tt]

awk -v RS= 'match($0,/VOLUMETABLE=".*"/){print substr($0,RSTART,RLENGTH)}' file1[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top