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!

processing delimited text file

Status
Not open for further replies.

uisneach

Programmer
Aug 9, 2004
1
US
I have been familiarising myself with awk but finding it tough going.

I have a | delimited text file in this format
S334387|165 WHEELER PL|3|3|0|0|4||2.0|||||305|||||||||||||||DISHWSHR|DISPOSAL|MICROWV|RANGE|REFRIG|WSHRDRYR||||||||0.0|COPPR|1353.0|CAMAINT|COMTAXES|HEAT cont...
S336759|105 Beeler PL|3|3|0|0|4||4.0|||||148|||||||||||||||DISHWSHR|DISPOSAL|MICROWV|RANGE|RANGEHD|REFRIG|||||||||COPPR|1703.0|CABLETV|CAMAINT|INSURNCE cont...

There are 150 fields in each row, some of which are empty. I need to rewrite each line grouping together certain columns to be just one column (Columns 15-28, 29-41, 45-60) and there are many other groupings i need to do in each row. However, its the same groupings to be done in each row of the text file.
e.g |0.5||DISHWSHR|DISPOSAL|MICROWV|RANGE| would become |0.5||DISHWSHR,DISPOSAL,MICROWV,RANGE|

My question has been sortof answered in this thread, but Ive had trouble tweaking the solution for what i want to do.

Many Thanks!!!
 
A starting point:
c15_28=$15;for(i=16;i<=28;++i)c15_28=c15_28","$(i)
Feel free to come back with what you have so far explaining where you're stuck.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
A different approach...
Code:
   [B]BEGIN[/B] [COLOR=#4444FF][B]{[/B][/color]
      [B]FS[/B] = [COLOR=#008000]"|"[/color];
      sep = [COLOR=#008000]"|||,,,||,||"[/color]; [COLOR=#444444]#..etc[/color]
   [COLOR=#4444FF][B]}[/B][/color]
   [COLOR=#4444FF][B]{[/B][/color]
      [B]for[/B] [COLOR=#4444FF][B]([/B][/color]x = 1 ; x < [B]NF[/B] ; x++[COLOR=#4444FF][B])[/B][/color]
         [COLOR=#a52a2a][B]printf[/B][/color] $x [COLOR=#a52a2a][B]substr[/B][/color][COLOR=#4444FF][B]([/B][/color]sep, x, 1[COLOR=#4444FF][B])[/B][/color];
      [COLOR=#a52a2a][B]print[/B][/color] $[B]NF[/B];
   [COLOR=#4444FF][B]}[/B][/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top