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

Fetching fields from multiple records using AWK ?

Status
Not open for further replies.

aej1973

IS-IT--Management
Apr 24, 2008
1
0
0
Hi, I have a text file as shown below. I need to use the awk utility and get the following output;

************required output****************
886-1 first_name monthly_amt tax_amt
886-2 first_name monthly_amt tax_amt
886-3 first_name monthly_amt tax_amt
********************************************

The main file is in the folloing format:-

*********Main file format*************

8861-1 first_name;last_name street#
monthly_amt balance_due late_fee
tax_amt packages
8861-2 first_name;last_name street#
monthly_amt balance_due late_fee
tax_amt packages
8861-3 first_name;last_name street#
monthly_amt balance_due late_fee
tax_amt packages

***************************************
I use the following script to pull up info from the first line;
cat ./sedFinal.txt |awk '/886/{print $1,$2}'|more

but I need to pull up info from multiple lines. How can this be done? Thanks for the help.

A
 
A starting point:
awk '/886/{split($2,a,";");x=$1" "a[1];getline;y=$1;getline;print x,y,$1}' sedFinal.txt | more

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Not requested, but sed is fun:

sed '
/^[0-9]\{1,\}-[0-9]\{1,\}/{
s/;.*//
N
s/\n\([^ ]*\) .*/ \1/
N
s/\n\([^ ]*\) .*/ \1/
}' sedFinal.txt

Cheers,
ND [smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top