![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find and replace string in a directory files | koti_rama | Shell Programming and Scripting | 2 | 05-30-2008 12:48 AM |
| shell script to find and replace string in multiple files | pharos467 | Shell Programming and Scripting | 10 | 05-20-2008 08:39 AM |
| Find and Replace in multiple files (Shell script) | jatins_s | Shell Programming and Scripting | 13 | 11-05-2007 10:11 AM |
| Find and replace files in multiple folders | lodey | Shell Programming and Scripting | 6 | 09-27-2007 11:00 PM |
| How to replace a string in multiple textfiles? | dwidmer | UNIX for Dummies Questions & Answers | 1 | 11-21-2003 02:13 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Find and replace a string in multiple files
I used the following script
cd pathname for y in `ls *`; do sed "s/ABCD/DCBA/g" $y > temp; mv temp $y; done and it worked fine for finding and replacing strings with names etc. in all files of the given path. I'm trying to replace a string which consists of path (location of file) say instead of ABCD i have to replace c:/mydocuments/pictures to d:/mypics/personal , as metacharacters wont be searched in unix this script is failing to replace the string which has a path in it. now my script is cd pathname for y in `ls *`; do sed "s/'c:/mydocuments/pictures'/'d:/mypics/personal'/g" $y > temp; mv temp $y; done i tired giving the path in single quotes and double quotes, but i see error sed: command garbled: s/'c:/mydocuments/pictures'/'d:/mypics/personal'/g And all the contents of the files in the path are erased. Is there any other way to work this out. Thanks |
| Forum Sponsor | ||
|
|
|
|||
|
Quote:
Code:
for y in *
do
sed "s/ABCD/DCBA/g" "$y" >temp
mv temp "$y"
done
Code:
sed "s/c:\/mydocuments\/pictures/d:\/mypics\/personal\/g/" |
| Tags |
| perl, perl regex, regex, regular expressions, sed |
| Thread Tools | |
| Display Modes | |
|
|