The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 9 06-08-2009 07:11 AM
shell script to find and replace string in multiple files pharos467 Shell Programming and Scripting 11 01-15-2009 11:40 AM
Replace a string containing :/=\ in files lalelle Shell Programming and Scripting 4 08-14-2008 09:26 AM
find and replace string in a directory files koti_rama Shell Programming and Scripting 2 05-30-2008 04:48 AM
Find and replace a string in multiple files pharos467 UNIX for Dummies Questions & Answers 2 11-05-2007 11:47 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2007
calredd calredd is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 9
Need to replace a string in 100's of files

Hi,
I have to parse 100's of files in a loop and replace a word called boston with a new word miami. I have to use korn shell scripting and I know grep, awk and also the looping part but I am not able to figure out how to implement the string replace part. I can vi each and every file but I want to automate this in a ksh using for loop. Appreciate your responces.
Thanks
Carl

ex: From:
cat file1.dat
city name is boston and country is USA.

To:
cat file1.dat
city name is miami and country is USA.

Like file1.dat, I have 100's of files in which I have to do string replace and preserve the same file name.
  #2 (permalink)  
Old 03-21-2007
calredd calredd is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 9
never mind

never mind, i figured out the solution. need to cat the files in a loop and pipe it to a sed to replace the word. such an easy implementation and it didnt strike me
  #3 (permalink)  
Old 03-21-2007
ennstate ennstate is offline
Registered User
  
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
But why do you need 'cat' and 'pipe' if sed can accept a file as argument.?? And still the sed 's output can be redirected to create a new file

Example:
PHP Code:
for file in /tmp//tmp//tmp/; do
sed 's/boston/MIAMI/g' ${file} > ${file}.new
done 
Thanks
Nagarajan Ganesan
  #4 (permalink)  
Old 03-21-2007
calredd calredd is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 9
yes it works that way too.. thanks for your reply.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0