The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with grep on search string in a txt file over multiple files m00 UNIX for Dummies Questions & Answers 2 05-18-2008 11:21 AM
last occurrence of a string across multiple files porphyrin UNIX for Dummies Questions & Answers 2 12-24-2007 05:39 AM
Find and replace a string in multiple files pharos467 UNIX for Dummies Questions & Answers 2 11-05-2007 07:47 PM
How can I rename multiple files depending on a string occuring in the filenames? karman UNIX for Dummies Questions & Answers 6 05-22-2007 11:29 AM
String replacement in multiple files WABonnett Shell Programming and Scripting 2 02-17-2004 11:49 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-09-2001
Registered User
 

Join Date: Nov 2001
Location: Texas
Posts: 1
Stumble this Post!
Question Editing one string in multiple files

I am trying to edit multiple files from one directory and including all the files in all the sub directories. My string opens each file, puts the text on my screen and does not save the new information to the file. I am using a variable in my script, and wondering if that is what is choking it.

so basically.... I have an instance of Bob in several files I want to rename to a variable name. the script asks for the variable and runs with it. But no output. Any ideas??

What I am using is this

find /path/$variable -print -exec sed -e "s/bob/$variable/" {} \;



Thank you!!
Forum Sponsor
  #2 (permalink)  
Old 11-09-2001
TioTony's Avatar
Bit Pusher
 

Join Date: Oct 2001
Location: Southern California
Posts: 332
Stumble this Post!
I think this is because you are not redirecting the output of sed back into the file, you are just displaying it. I don't know the syntax off the top of my head for the find command to do this but a script like this would work:

#!/bin/sh
files=`find /path/$variable -print `
for i in $files
do
sed -e "s/bob/$variable/" $i > $i.tmp
mv $i.tmp $i
done

I haven't tested this but it should get you in the neigborhood or give you an idea of what you need to modify with your current command.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0