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!

search for text over multiple lines? 2

Status
Not open for further replies.

kornShellScripter

Programmer
Apr 27, 2007
24
GB
Hi!

I have the following ASCII file, which is a report output from another system, in a spool directory in Unix:

<lines above snipped>
Amount One Amount Two Amount Three
---------- ---------- ------------
1000.00 2000.00 3000.00
<lines below snipped>

What I need my korn shell script to do is pick out the second "Amount Two" value. For example:

read through the file
until it finds the header line "Amount One Amount Two Amount Three"
then
skip ahead two lines # because next line is just dashes
echo the_line | nawk '{print $2}'
quit reading through the file
done


I'm struggling how to code this logic...
(and it's the only method I've come up with too - if you've a better way, please feel free)

Can you advise, please?
 
Hi

Code:
while read l; do [[ "$l" == *Amount\ Two* ]] && { read; read l l lx; echo "$l"; }; done < /input/file
Tested with (pd)[tt]ksh[/tt] and [tt]bash[/tt].

Feherke.
 
Another way:
nawk '/Amount Two/{getline;getline;print $2;exit}' /path/to/input

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top