Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output a file to itself ??

Status
Not open for further replies.

dbeez

Technical User
Aug 15, 2005
71
KR
Hi,

I am trying to make the output of a command on a file, feed itself into the same file ... in other words

sed -e -n 's/text//g' file1 > file1

... instead of getting an updated file1, containing only the new sorted text. I get a blank file1

I guess this must be a fairly simple question ... anyone have any ideas ???
 
sed doesn't work like that (as you've found out). Best thing to do is output to a temp file and then rename that to your original at the end.
 
Hi

GNU [tt]sed[/tt] version 4.1.2 :
man sed said:
-i[SUFFIX], --in-place[=SUFFIX] edit files in place (makes backup if extension supplied)
Code:
sed -i 's/text//g' file1

By the way. If you put -n, without a [tt]p[/tt] command of course your output file will be empty.

Feherke.
 
One portable way:
echo "1,\$s/text//g\nw" | ed -s file1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top