sed experts. Help
Emanoil Kotsev
deloptes at yahoo.com
Mon Oct 27 00:48:18 UTC 2008
Rick Knight wrote:
> Alexander Smirnov wrote:
>> Rick Knight wrote:
>>
>>> Sed experts,
>>>
>>> I have a bunch of php scripts, over 1000, that all need to have 1 line
>>> removed. The line begins with...
>>>
>>> <?php eval(base64_decode(
>>>
>>> and is at the top of each file. How would I construct a sed command to
>>> remove this line from every file in a directory and it's subs?
>>>
>>> Thanks,
>>> Rick
>>>
>>>
>>>
>> why sed? you can use excluding option of grep:
>> $grep - v "<?php eval(base64_decode( "
>> will match every line but not mentioned.
>>
>>
> Doesn't have to be sed. Sed just came to mind as a way to do what I need
> to do, remove a line of code from the top of several php files. I know
> how to use grep to find the line of text. How would I use grep to remove
> it? WOuld I pipe the output of grep to rm?
>
> Thanks,
> Rick
Then you can also use perl
perl -pi -e 's:^<?php /\*\*\/eval(base64_decode(.*$::g' *.php
with *.php~ instead of *.php you will get a backup file for each *.php file
which was edited.
I prefer also using different chars as command mark like ':' or '"'. It
makes it easy to read.
have a look at perlrun (man perlrun)
========= quote =========
This allows you to add a prefix to the backup file, instead of
(or in addition to) a suffix:
$ perl -pi'orig_*' -e 's/bar/baz/' fileA # backup
to 'orig_fileA'
Or even to place backup copies of the original files into
another directory (provided the directory already
exists):
$ perl -pi'old/*.orig' -e 's/bar/baz/' fileA # backup
to 'old/fileA.orig'
These sets of one-liners are equivalent:
$ perl -pi -e 's/bar/baz/' fileA # overwrite
current file
$ perl -pi'*' -e 's/bar/baz/' fileA # overwrite
current file
$ perl -pi'.orig' -e 's/bar/baz/' fileA # backup
to 'fileA.orig'
$ perl -pi'*.orig' -e 's/bar/baz/' fileA # backup
to 'fileA.orig'
=============================
More information about the kubuntu-users
mailing list