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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

623 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