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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Processing between 2 expressions

Status
Not open for further replies.

brownjd

MIS
Oct 5, 2001
6
0
0
US
Wondering if anyone has had to process between 2 different expressions using either awk or sed. I'm looking at finding a line with a specific customer number, then capturing the lines following until it hits the next line containing "customer number" which may or may not be the same customer number.
 
samples PLS!!!! vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Sure...;-)
Shipto Customer: 111111111
lineitem 1244444444
number sold 444444
address
city
zip
Shipto Customer: 99987000
lineitem 09999
number sold 999
address
city
zip
Shipto Customer: 111111111
lineitem 678884
number sold 444444
address
city
zip

 
something like that should get you started:

nawk -f customers.awk customers.txt

#------------------- customers.awk
/Shipto Customer:/ {printf(&quot;Customer: %s\n&quot;, $NF);next}
{
printf(&quot;\t&quot;);
for(i=1; i<NF; i++)
printf(&quot;%s%s&quot;, $i, OFS);

if ( NF > 1)
printf(&quot;[%s]\n&quot;, $NF);
else
printf(&quot;%s\n&quot;, $NF);
}
vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top