Link to home
Start Free TrialLog in
Avatar of ttheimer
ttheimer

asked on

How to use sed to change file contents

New to sed... I have the following statement that when entered on the command line works properly to make the desired replacement.  This version sends the result to stdout.  I can also redirect to a new file by appending ">newfile".  But I want to change the original file and when I redirect to the same file name I get an empty file.  What am I missing?  How do I change the original file?

sed '/^<script language=javascript><\!-- /,/^ -->/c<body>' sedtesttarget.html

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of ewest02
ewest02
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ttheimer
ttheimer

ASKER

The --in-place (or -i) option was not noted in my [paper] reference text - found it in the man file.  Works perfectly.  Thanks.

New command:

sed --in-place '/^<script language=javascript><\!-- /,/^ -->/c<body>' sedtesttarget.html
The --in-place (or -i) option was not noted in my [paper] reference text - found it in the man file.  Works perfectly.  Thanks.

New command:

sed --in-place '/^<script language=javascript><\!-- /,/^ -->/c<body>' sedtesttarget.html