From: gioparl on
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
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

Ο/Η 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
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
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.