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!

put parts of duplicate lines together

Status
Not open for further replies.

ruebensau

Programmer
Dec 14, 2005
3
DE
Hallo,
I have searched the forum, but i have not found the answer to this little problem.
I have the following comma seperated Inputfile with a fix fieldnumber of 5:

19/100,aaa,123,wert,bluebird.dgn
19/100,aaa,123,wert,bluebird.oce
19/100,aaa,123,wert,bluebird.tif
19/121,a3e,144,zzzz,coffehou.dgn
19/231,er4,444,53zr,fingercl.pdf
19/649,2tt,gt6,gt67,streetwa.dgn
19/699,bbb,ggg,jjjj,highway1.dgn
19/699,bbb,ggg,jjjj,highway1.tif
...

I want to receive the output below:

19/100,aaa,123,wert,bluebird.dgn,wert,bluebird.oce,wert,bluebird.tif
19/121,a3e,144,zzzz,coffehou.dgn
19/231,er4,444,53zr,fingercl.pdf
19/649,2tt,gt6,gt67,streetwa.dgn
19/699,bbb,ggg,jjjj,highway1.dgn,jjjj,highway1.tif
...

The uniq-key field is field 1.
You can see, that i want to delete the duplicate lines except one. Field 4 and 5 should be put at the end of the line.

Do you have any idea?
I am using windows and the awk.exe file.
Thx

 
Hi

Put this in a file, lets say "script.awk" :
Code:
BEGIN {
  FS=","
}
{
  if (u==$1) printf f
  else {
    u=$1
    f=$4 "," $5
    printf "\n" $0
  }
}
And use it this way :
Code:
awk.exe -f script.awk inputfile
As far as I can remember, this should work on Windows.

Feherke.
 
A starting point:
script.awk
Code:
{a[$1","$2","$3]=a[$1","$2","$3]","$4","$5}
END{for(i in a)print i a[i]}

awk -F, -f script.awk input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank you, it works perfectly and only 2 lines sourcecode^^
Actually, i was awaiting a larger program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top