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

formatting help

Status
Not open for further replies.

billbose

Programmer
Jan 15, 2001
66
US
Hi awk experts,

I have a file with some duplicate first fields like as follows:

shop | greg | 21
shop | bill | 23
work | jane | 26

I want the desired o/p to be as:
shop | greg bill | 21
| | 23
work | jane | 26

Could somebody help me?
Note: the pipes are just field seperators, ignore them.
TIA

Regards,
Bill
 
awk -F"|" '{
if( arr[ $1] == "") {
ii++
carr[ ii] = $1
arr[ $1] = $0
}
else {
split( arr[ $1], art)
art[2] = art[2] "" $2
arr[ $1] = art[1] "|" art[2] "|" art[3]
}
}
END{
for( jj = 1; jj <= ii; jj++) print arr[ (carr[ jj])]}' Yourfile

I hope it works on solaris nawk.
I use HPUX.

Succes Bill

Gregor.Weertman@mailcity.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top