![]() |
|
|
|
|
|||||||
| 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 |
| A simple query on unix shell script | shekhar_ssm | Shell Programming and Scripting | 2 | 01-23-2008 08:41 AM |
| Simple to you not simple to me pattern matchin help | aleks001 | Shell Programming and Scripting | 0 | 07-22-2007 07:06 PM |
| Simple loop query | kutz13 | UNIX for Dummies Questions & Answers | 2 | 07-17-2007 12:13 PM |
| Simple C question... Hopefully it's simple | Xeed | High Level Programming | 6 | 12-15-2006 11:29 AM |
| Ok simple question for simple knowledge... | Corrail | UNIX for Dummies Questions & Answers | 1 | 11-28-2005 10:03 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
simple sed query
hi,
i would like to replace a string in a series of files with another string, without outputting to new files. is this possible? i've tried using sed, and started by trying to alter the contents of one file... sed 's/string1/string2/g' file.txt but while this does the replacement on screen, the file is not altered. any ideas...please? and how could i get this to work on *.txt? |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
There's no way that I know of to do that without using a temporary file.. if you want to manipulate several files, you'll need a loop:
Code:
for FILE in `ls *.txt` do sed 's/string1/string2/g' < $FILE > TMP_00 mv TMP_00 $FILE done |
|
#3
|
|||
|
|||
|
We can do this using perl. If you are not very particular about sed, you may use the following
perl -p -i -e "s/string1/string2/g" file1 |
|||
| Google The UNIX and Linux Forums |