using sed to edit a file

lightweight

Senior member
Aug 31, 2004
473
0
71
I have my expression written and it works when I send the output to a new file:
ex: sed 'expression' input > output

What I want to do is just use: sed 'expression' input

I don't want to rename the file, I just want the operation to be performed on that file. All it does is delete lines that match a certain criteria. How can I do this?
 

stevf

Senior member
Jan 26, 2005
290
0
0
i am at work and dont have time to look up stuff and work is xp so no man pages either - but here goes:

Are you trying to save the changes in the original file? and if you try that via redirection, does it give you an empty file? try using man and see if there is a -i option and use that . I recently did that and pretty sure it was sed but cant check right now - will be able to this evening - so try something like this

sed 'expression' -i inputFile
 

nweaver

Diamond Member
Jan 21, 2001
6,813
1
0
some versions of sed don't work for this (I think there was a bug for a while)
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
Output to a different file and move the changed file. Or copy the input file to a temp file and run sed on it. Its more portable this way.