Hi all,
I here have a file which contains a list of files inside, all of which have the suffix ".log".
And now I would wish to replace all the pattern ".log" with ".log.bz2" there. So how could I archive this?
Thanks
Hi all,
I here have a file which contains a list of files inside, all of which have the suffix ".log".
And now I would wish to replace all the pattern ".log" with ".log.bz2" there. So how could I archive this?
Thanks
In vi:
<ESC> (to go into command mode)
:%s/.log/.log.bz2/g
Using sed:
sed 's/.log/.log.bz2/' filename > filename.new
Hi Gary,
A sample of my entry is,
/logs/dvgbiau/batch/unit_test-20120131_000943.log
If I use sed 's/.log/.log.bz2/' filename > filename.new to make the replacement, it will become
.log.bz2s/dvgbiau/batch/unit_test-20120131_000943.log
However I'm expecting something like below?
/logs/dvgbiau/batch/unit_test-20120131_000943.log.bz2
Thanks
All you need is to include an 'achor' in the pattern to say only match .log at the end of the line.
In vi:
<ESC> (to go into command mode)
:%s/.log$/.log.bz2/
Using sed:
sed 's/.log$/.log.bz2/' filename > filename.new
Btw, in sed, you can edit the file in place by
sed -i 's/.log$/.log.bz2/' filename
my apologies, use this:
sed 's/\.log/\.log\.bz2/' filename > filename.new
the "dot" is significant in a regular expression and should be escaped with the backslash to take away its special meaning.