Go Premium for a chance to win a PS4. Enter to Win


Overwriting  Original file with new output ?

Posted on 2006-06-25
Medium Priority
Last Modified: 2010-04-22
I am running  sed -f test.sed $file > $file.out              as a result I am getting .out files

( which is the expected output ) but i have to mannually rename them to the original filename
then remove all*.out

is there a way I can overwrite the original one ?  Thanks much


My whole script look like following :

for file in `echo *`
  sed -f test.sed $file > $file.out
Question by:dmshawkat
LVL 38

Accepted Solution

yuzh earned 100 total points
ID: 16980763
you can change:
    sed -f test.sed $file > $file.out

    sed -f test.sed $file > $file.out
    mv $file.out $file
LVL 48

Assisted Solution

Tintin earned 100 total points
ID: 16988646
Always good to check the sed was successful *before* overwriting the original file.  I'd use

for file in *
  sed -f test.sed $file >file.out && mv file.out $file

Note that `echo *` is redundant as the shell does globbing for you.
LVL 27

Expert Comment

ID: 17006381
It's possible with 'ed' command. man ed

cat test.ed | ed - $file

ed commands are different from sed, so you need to modify script.

Very simple 'ed' script, that will add '1234' to the end of each line is:

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question