Help for shell

hi,

I need some help for shell.
How can modify a file to get
the same lines appended
the same line with some pattern modified
(exemple below)

Thanks for your help ...

before:
aaaazzzzaaaa
bbbbzzzzbbbb
cccczzzzcccc
ddddzzzzdddd


after:
aaaazzzzaaaa aaaayyyyaaaa
bbbbzzzzbbbb bbbbyyyybbbb
cccczzzzcccc ccccyyyycccc
ddddzzzzdddd ddddyyyydddd
Patrice [ Mo, 12 November 2007 21:49 ] [ ID #1868203 ]

Re: Help for shell

astalavista wrote:
> hi,
>
> I need some help for shell.
> How can modify a file to get
> the same lines appended
> the same line with some pattern modified
> (exemple below)

Use paste(1), sed(1), and a shell with process substitution...

paste data-file <( sed 's/zzzz/yyyy/' data-file )


Janis

>
> Thanks for your help ...
>
> before:
> aaaazzzzaaaa
> bbbbzzzzbbbb
> cccczzzzcccc
> ddddzzzzdddd
>
>
> after:
> aaaazzzzaaaa aaaayyyyaaaa
> bbbbzzzzbbbb bbbbyyyybbbb
> cccczzzzcccc ccccyyyycccc
> ddddzzzzdddd ddddyyyydddd
>
>
>
Janis Papanagnou [ Di, 13 November 2007 00:19 ] [ ID #1868993 ]

Re: Help for shell

Janis Papanagnou wrote:
> astalavista wrote:
>
>> hi,
>>
>> I need some help for shell.
>> How can modify a file to get
>> the same lines appended
>> the same line with some pattern modified
>> (exemple below)
>
>
> Use paste(1), sed(1), and a shell with process substitution...
>
> paste data-file <( sed 's/zzzz/yyyy/' data-file )

Or use awk...

awk '{x=$0; sub(/zzzz/,"yyyy"); print x,$0}' data-file

(Use printf() or a change the output field separator OFS for other
output formats.)

Janis

>>
>> Thanks for your help ...
>>
>> before:
>> aaaazzzzaaaa
>> bbbbzzzzbbbb
>> cccczzzzcccc
>> ddddzzzzdddd
>>
>>
>> after:
>> aaaazzzzaaaa aaaayyyyaaaa
>> bbbbzzzzbbbb bbbbyyyybbbb
>> cccczzzzcccc ccccyyyycccc
>> ddddzzzzdddd ddddyyyydddd
>>
>>
>>
Janis Papanagnou [ Di, 13 November 2007 00:23 ] [ ID #1868994 ]

Re: Help for shell

OK thanks ..

"Janis Papanagnou" <Janis_Papanagnou [at] hotmail.com> a écrit dans le message de
news: fhan9n$ktq$1 [at] online.de...
> Janis Papanagnou wrote:
>> astalavista wrote:
>>
>>> hi,
>>>
>>> I need some help for shell.
>>> How can modify a file to get
>>> the same lines appended
>>> the same line with some pattern modified
>>> (exemple below)
>>
>>
>> Use paste(1), sed(1), and a shell with process substitution...
>>
>> paste data-file <( sed 's/zzzz/yyyy/' data-file )
>
> Or use awk...
>
> awk '{x=$0; sub(/zzzz/,"yyyy"); print x,$0}' data-file
>
> (Use printf() or a change the output field separator OFS for other
> output formats.)
>
> Janis
>
>>>
>>> Thanks for your help ...
>>>
>>> before:
>>> aaaazzzzaaaa
>>> bbbbzzzzbbbb
>>> cccczzzzcccc
>>> ddddzzzzdddd
>>>
>>>
>>> after:
>>> aaaazzzzaaaa aaaayyyyaaaa
>>> bbbbzzzzbbbb bbbbyyyybbbb
>>> cccczzzzcccc ccccyyyycccc
>>> ddddzzzzdddd ddddyyyydddd
>>>
>>>
>>>
Patrice [ Di, 13 November 2007 21:33 ] [ ID #1869036 ]
Linux » comp.unix.shell » Help for shell

Vorheriges Thema: capturing a return code
Nächstes Thema: [gnu.bash.bug] BASH Frequently-Asked Questions (FAQ version 3.36)