sed over writes my original file (using sed to remove leading spaces)

Hello and thx for reading this

I'm using sed to remove only the leading spaces in a file

bash-280R# cat foofile
some text
 some text
 some text
some text
some text
bash-280R#

bash-280R# sed 's/^ *//' foofile > foofile.use

bash-280R# cat foofile.use
some text
some text
some text
some text
some text
bash-280R#

That works great, however I really don't want to rename the file.
I was hoping this would work

bash-280R# sed 's/^ *//' foofile > foofile

It just overwrites foofile and makes it blank.

Is there a way to get around this and keep the original file name w/ the modification of removing leading spaces.

I will be running sed in a script

Thank you for your help

L.

Some versions of sed have a '-i' option for in-place editing. Check your man page to see if it's available on your system.

Example:

sed -i  -e 's/^ *//' foofile

You are clobbering the file before the modification.

Thanks for your help. No -i option, looks like I'm stuck renameing the file.

OPTIONS
The following options are supported:

 -e script       script is an edit command for sed. See USAGE
                 below  for more information on the format of
                 script. If there is just one -e  option  and
                 no -f options, the flag -e may be omitted.

 -f script_file  Takes   the   script    from    script_file.
                 script_file  consists  of  editing commands,
                 one per line.

 -n              Suppresses the default output.

not really, just use perl instead:

perl -pi -e 's/^ *//' foofile
sed 's/^ *//' foofile > foofile.use ; mv foofile.use foofile

Which would execute the sed on the original file, to a new filename. Then, it would move the new file to the original.

Thank you very much for the help and even the Perl solution.

I hope this information helps others too.

Thanks

L.