Sed Editor

0 pts.
Tags:
DataCenter
Development
Linux
Unix
Hi, can someone please tell me if it's possible to run a sed substitution against multiple files and have the change saved back to the original file name. At the moment I can only find how to write the output to a specified file name. Thanks
ASKED: May 9, 2005  7:06 AM
UPDATED: May 13, 2005  5:42 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

First off, it’s not safe – unless there’s a temporary file name in the middle.

When you’ve got a file open for reading (sed input), you don’t want to be writing to the same output file. Most likely outcomes would be file truncation or file corruption.

You don’t specify if you’re running in a *nix environment or a windows or cygwin environment. But it might go something like this…
$file=original_file_name
sed s/oldstuff/newstuff < $file > tempfile
cp -f tempfile $file

Bear in mind that the syntax might not be quite right, since I just did this off the top of my head. You can also have the original filename passed as a parameter to the shell script.

Bob

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following