|
Prev: Have script redirect output?
Next: Need to convert DOS to UNIX with a *limited* set of UNIX commands
From: gioparl on 9 Mar 2006 04:47 hello! I have some files with fixed-size records george jenny lina I want to convert to george ,jenny ,lina how can do it?sed&awk??any help? thanks! p.s. it's spaces between fields,not tabs.
From: Vino on 9 Mar 2006 05:13 gioparl(a)gmail.com wrote: > hello! > > I have some files with fixed-size records > > george jenny lina > > I want to convert to > > george ,jenny ,lina > > how can do it?sed&awk??any help? > > thanks! > > p.s. it's spaces between fields,not tabs. > sed -e "s_ \([^ ]\)_,\1_g" --.
From: gioparl on 9 Mar 2006 06:05 Ο/Η Vino ÎγÏαψε: > gioparl(a)gmail.com wrote: > > hello! > > > > I have some files with fixed-size records > > > > george jenny lina > > > > I want to convert to > > > > george ,jenny ,lina > > > > how can do it?sed&awk??any help? > > > > thanks! > > > > p.s. it's spaces between fields,not tabs. > > > sed -e "s_ \([^ ]\)_,\1_g" > thanks a lot! it works:) but if a field contains two strings seperated by a space? I would like to use it with parameters(positions) is there a way to use positions position 23,56,88 insert a comma something like that any idea? > --.
From: Stephane Chazelas on 9 Mar 2006 06:17 On 9 Mar 2006 03:05:46 -0800, gioparl(a)gmail.com wrote: > > ?/? Vino ??????: >> gioparl(a)gmail.com wrote: >> > hello! >> > >> > I have some files with fixed-size records >> > >> > george jenny lina >> > >> > I want to convert to >> > >> > george ,jenny ,lina >> > >> > how can do it?sed&awk??any help? >> > >> > thanks! >> > >> > p.s. it's spaces between fields,not tabs. >> > >> sed -e "s_ \([^ ]\)_,\1_g" >> > > > thanks a lot! it works:) > > but if a field contains two strings seperated by a space? > I would like to use it with parameters(positions) > is there a way to use positions > > position 23,56,88 insert a comma > something like that [...] You could do it as: TAB=`printf '\t'` < file unexpand -t 14 | sed "s/$TAB/&,/g" | expand -t 14 (or | expand -t 13,27) or < file sed 's/^\(.\{13\}\) \(.\{13\}\) /\1,\2,/' -- Stephane
From: Ed Morton on 9 Mar 2006 17:39 gioparl(a)gmail.com wrote: > ?/? Vino ??????: > >>gioparl(a)gmail.com wrote: >> >>>hello! >>> >>>I have some files with fixed-size records >>> >>>george jenny lina >>> >>>I want to convert to >>> >>>george ,jenny ,lina >>> >>>how can do it?sed&awk??any help? >>> >>>thanks! >>> >>>p.s. it's spaces between fields,not tabs. >>> >> >>sed -e "s_ \([^ ]\)_,\1_g" >> > > > > thanks a lot! it works:) > > but if a field contains two strings seperated by a space? > I would like to use it with parameters(positions) > is there a way to use positions > > position 23,56,88 insert a comma > something like that > > any idea? GNU awk can support you with fixed width fields. All awks have length(), substr(), etc. functions you could use. Ed.
|
Next
|
Last
Pages: 1 2 3 Prev: Have script redirect output? Next: Need to convert DOS to UNIX with a *limited* set of UNIX commands |