If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Hi need help in shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-30-04, 04:34
arunprasadlv arunprasadlv is offline
Registered User
 
Join Date: Mar 2004
Location: India
Posts: 41
Hi need help in shell script

Hi
I want to replace a perticular word say "Console" with "DEBUG" present in the file.The word may appear any number of times in the file.

I tried to solve the problem using tr command.

tr "$wordtosearch" "$wordtoreplace" < $Filename| cat > $Filename


But it is not giving the output which i want.



Pls reply back Immediately.


Regds,
Arun
Reply With Quote
  #2 (permalink)  
Old 03-30-04, 08:05
aigles aigles is offline
Registered User
 
Join Date: Jan 2004
Location: Bordeaux, France
Posts: 319
The tr command deletes or substitutes characters from standard input and writes the result to standard output.

If you execute the command "tr 'Console' 'DEBUG'", you substitute characters 'C','o','n','s','o','l','e' by 'D','E','B','U','G','',''
For example :
Input: La Console systeme
Output: La DGBUGle UyUteme

Use sed or perl:
Code:
sed "s/$wordtosearch/$wordtoreplace/g"  input_file > temp_file
mv temp_file input_file

perl -p -i -e "s/$wordtosearch/$wordtoreplace/g" input_file
If the character '/' is part of one of the two strings (search or replace), you must change it by another, for example :
Code:
sed "s!$wordtosearch!$wordtoreplace!g" input_file > output_file
__________________
Jean-Pierre.
Reply With Quote
  #3 (permalink)  
Old 03-30-04, 08:55
arunprasadlv arunprasadlv is offline
Registered User
 
Join Date: Mar 2004
Location: India
Posts: 41
Thanks Aigles for ur timely response.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On