Overwriting  Original file with new output ?

Posted on 2006-06-25
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 38

Accepted Solution

yuzh earned 25 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 25 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

751 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