Solved

Overwriting  Original file with new output ?

Posted on 2006-06-25
5
377 Views
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

Shawkat

My whole script look like following :


#!/bin/ksh
for file in `echo *`
 do
  sed -f test.sed $file > $file.out
 done
#
0
Comment
Question by:dmshawkat
5 Comments
 
LVL 38

Accepted Solution

by:
yuzh earned 25 total points
Comment Utility
you can change:
    sed -f test.sed $file > $file.out
to:

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

Assisted Solution

by:Tintin
Tintin earned 25 total points
Comment Utility
Always good to check the sed was successful *before* overwriting the original file.  I'd use

#!/bin/ksh
for file in *
do
  sed -f test.sed $file >file.out && mv file.out $file
done

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

Expert Comment

by:Nopius
Comment Utility
It's possible with 'ed' command. man ed

Usage:
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:
--[cut]--
1,$s/$/1234/
w
q
--[cut]--
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now