The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 02:21 PM
last occurrence of a string across multiple files porphyrin UNIX for Dummies Questions & Answers 2 12-24-2007 09:39 AM
Find and replace a string in multiple files pharos467 UNIX for Dummies Questions & Answers 2 11-05-2007 11: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 02:29 PM
String replacement in multiple files WABonnett Shell Programming and Scripting 2 02-17-2004 03:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-09-2001
Skoshi Skoshi is offline
Registered User
  
 

Join Date: Nov 2001
Location: Texas
Posts: 1
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!!
  #2 (permalink)  
Old 11-10-2001
TioTony's Avatar
TioTony TioTony is offline Forum Advisor  
Bit Pusher
  
 

Join Date: Oct 2001
Location: Southern California
Posts: 332
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.
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 02:44 PM.


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