Unix Shell - Replacing a word in string

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > January 2007 > Replacing a word in string





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Replacing a word in string
Rafael The Engel

2007-01-28, 1:17 pm

Hello,
I need to replace a word in string but the only problem is that the
word is repeating on itself a couple of times.
and I need to replace just one show of this word

example:
insert into TEST
values('TEXT','Y',NULL,'N',NULL,'5','0',
NULL,NULL,'N',NULL,'N',NULL,NUL
L,NULL,NULL,NULL,NULL,NULL,SYSDATE,SYSDA
TE,'OP');

I need to change just the first NULL to " '&yuyu' "

any help would be appreciated

Rafael

Stephane CHAZELAS

2007-01-28, 1:17 pm

2007-01-28, 06:26(-08), Rafael The Engel:
> Hello,
> I need to replace a word in string but the only problem is that the
> word is repeating on itself a couple of times.
> and I need to replace just one show of this word
>
> example:
> insert into TEST
> values('TEXT','Y',NULL,'N',NULL,'5','0',
NULL,NULL,'N',NULL,'N',NULL,NUL
> L,NULL,NULL,NULL,NULL,NULL,SYSDATE,SYSDA
TE,'OP');
>
> I need to change just the first NULL to " '&yuyu' "

[...]

To change the first NULL of each line:

sed "s/NULL/ '\&yuyu' /" < input-file.txt

To only change the second of each line:

sed "s/NULL/ '\&yuyu' /2"

to change the first NULL of the whole file:

sed -e '/NULL/!b' -e "s// '\&yuyu' /" -e :1 -e n -e b1

Or

perl -0777 -pe "s/NULL/ '&yuyu' /"

--
Stéphane
Rafael The Engel

2007-01-29, 1:32 am

Thank you very much, it work's great.

On Jan 28, 4:39 pm, Stephane CHAZELAS <this.addr...@is.invalid> wrote:
> 2007-01-28, 06:26(-08), Rafael The Engel:> Hello,
>
>
>
> To change the first NULL of each line:
>
> sed "s/NULL/ '\&yuyu' /" < input-file.txt
>
> To only change the second of each line:
>
> sed "s/NULL/ '\&yuyu' /2"
>
> to change the first NULL of the whole file:
>
> sed -e '/NULL/!b' -e "s// '\&yuyu' /" -e :1 -e n -e b1
>
> Or
>
> PERL -0777 -pe "s/NULL/ '&yuyu' /"
>
> --
> St=E9phane


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com