Replacing a word in string
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Replacing a word in string




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Replacing a word in string  
Rafael The Engel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-28-07 06: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






[ Post a follow-up to this message ]



    Re: Replacing a word in string  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-28-07 06: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





[ Post a follow-up to this message ]



    Re: Replacing a word in string  
Rafael The Engel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-29-07 06: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






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 11:32 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register