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!

joining lines 1

Status
Not open for further replies.

subok

MIS
Feb 21, 2005
37
BE
Hi,

I'm having trouble joining several lines into one record. When MSIN is found then join the second
field of the first 3 lines and first field of the succeeding lines until MSIN found. Having the following input file format :


MSIN: 7100000000
NDC: 721
TELEPHON 247307
TS21 247307
TS22 247307
BS26 247307
MSIN: 7100000001
NDC: 721
TELEPHON 336771
TS21 336771
TS22 336771
MSIN: 7100000005
NDC: 721
TELEPHON 244825
TS21 244825
TS22 244825
MSIN: 7100000006
NDC: 721
TELEPHON 242664 TS11
BS26 506046 U26T8N1I
TS21
TS22

******* OUTPUT *****************************

7100000000 721 247307 TS21 TS22 BS26
7100000001 721 336771 TS21 TS22
7100000005 721 336771 TS21 TS22
7100000006 721 242664 BS26 TS21 TS22

*****************************************

Thanks
 
You may try something like this:
awk '
/^MSIN:/{if(f)dump();++f;msin=$2;next}
/^NDC:/{ndc=$2;next}
/^TELEPHON/{tel=$2;next}
{ts=ts" "$1}
END{if(f)dump()}
function dump(){
print msin" "ndc" "tel ts
f=0;msin=ndc=tel=ts=""
}' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Code:
/MSIN/ { show(s); s = ""; count = 1 }
count && count < 4 { s = s $2 FS }
count > 3 { s = s $1 FS }
{ count++ }
END { show(s) }
function show(s)
{ sub(/ +$/,"",s);  if (s) print s
}
 
guys! both of them works

thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top