Computing.Net > Forums > Unix > Search And Replace With Sed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Search And Replace With Sed

Reply to Message Icon

Name: James Gordon
Date: September 18, 2002 at 23:55:14 Pacific
OS: Sun Solaris
CPU/Ram: Unknown
Comment:

Hi,

I intend to do a search and replace for specific words for files under a directory (inclusive of subdirectories).

I know how to do that file by file using sed
and redirect it to the original file. But now, I need to search for multiple files and update accordingly.

Please help.


Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: tom z.
Date: September 19, 2002 at 03:14:46 Pacific
Reply:

Maybe a for loop with a variable for your filenames generated by ls?

foreach file (`ls`)
do
whatever $file
done


0

Response Number 2
Name: David Perry
Date: September 19, 2002 at 05:31:38 Pacific
Reply:

for pattern in "string1" "string2" ; do
for file in `find /full/path/root/to/search/ -exec grep -l $pattern {} \;` ; do
ls -l $file ;
sed -e 's/$pattern/newpattern/' $file > $file.tmp
mv $file.tmp $file
done ;
done | mail user@domain.com


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Search And Replace With Sed

Search and replace string in files www.computing.net/answers/unix/search-and-replace-string-in-files/7857.html

Unix - Search and replace www.computing.net/answers/unix/unix-search-and-replace/6775.html

Find and replace with sed or awk www.computing.net/answers/unix/find-and-replace-with-sed-or-awk/8099.html