sed experts. Help

Rick Knight rick_knight at rlknight.com
Thu Oct 23 18:02:40 UTC 2008


Jared Greenwald wrote:
> Don't forget that when using the -exec option to find {} is the
> currently-found file/object and you need to end your command with \;
>
> If you were to be just looking for php files to update...
>
> find <dir> -type f -name "*.php" -exec sed -i.bak "/^<?php
> \/\*\*\/eval(base64_decode(/d" {} \;
>
> Where <dir> is the top of the directory where all of this is residing.
>   
Thanks Jared, I had tried -name *.php, but I had not added the quotes.

Thanks,
Rick

> On Thu, Oct 23, 2008 at 1:37 PM, Rick Knight <rick_knight at rlknight.com> wrote:
>   
>> Glenn R Williams wrote:
>>     
>>> To add a backup file, just put the suffix you want after the "-i" option. In
>>> this example, I have sed name backup files with a ".bak" suffix:
>>>
>>> sed -i.bak "/^<?php \/\*\*\/eval(base64_decode(/d" file*.txt
>>>
>>> Glenn
>>>
>>>       
>> One more question, How can I make this command work recursively. I tried
>> just adding "find <dir> -type f exec"  to the front of the command but
>> it gives an error...
>>
>> find: missing argument to `-exec'
>>
>> I've also added the file exstension to Jarreds command but that also
>> gives an error...
>>
>> find: paths must precede expression.
>>
>> How can I combine recursive function and the file extension? There are
>> several .html and .cfg files that don't need to fixed, so I would like
>> to avoid them if possible.
>>
>> Thanks,
>> Rick
>>     
>>> On Thursday 23 October 2008 13:04:17 Rick Knight wrote:
>>>
>>>       
>>>> Glenn R Williams wrote:
>>>>
>>>>         
>>>>> Jared,
>>>>>
>>>>> sed -i '/^<?php eval(base64_decode(.*/d' *.php
>>>>>
>>>>>           
>>>> can I add .bak to this command to have it backup the files?
>>>>
>>>>
>>>>         
>>>>> will update all files in place, deleteing all lines beginning with:
>>>>>
>>>>> <?php eval(base64_decode(
>>>>>
>>>>>           
>>>> This should have been <?php /**/eval(base64_decode (my mistake). How
>>>> would I add /**/ to this command?
>>>>
>>>>
>>>>         
>>>>> Make a backup first, since this is a very poerful command!
>>>>>
>>>>>
>>>>> HTH,
>>>>>
>>>>> Glenn
>>>>>
>>>>> On Thursday 23 October 2008 00:54:10 Jared Greenwald wrote:
>>>>>
>>>>>           
>>>>>> there's nothing that says you need to do all the files in one sed
>>>>>> command, right?
>>>>>>
>>>>>> something like this should work...
>>>>>>
>>>>>> find <dir> -type f -exec sed -i.bak 's/^<?php eval(base64_decode(.*.$//'
>>>>>> {} \;
>>>>>>
>>>>>> ...Not only will it do all the line removal, it will also make backups
>>>>>> (as <file>.bak) so if you screw up you will have the original files to
>>>>>> revert.
>>>>>>
>>>>>> -Jared
>>>>>>
>>>>>> On Thu, Oct 23, 2008 at 12:22 AM, Rick Knight <rick_knight at rlknight.com>
>>>>>>
>>>>>>             
>>>>> 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
>>>>>>>
>>>>>>> --
>>>>>>> kubuntu-users mailing list
>>>>>>> kubuntu-users at lists.ubuntu.com
>>>>>>> Modify settings or unsubscribe at:
>>>>>>> https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
>>>>>>>
>>>>>>>               
>>>> Thanks,
>>>> Rick
>>>>
>>>>         
>>>       
>> --
>> kubuntu-users mailing list
>> kubuntu-users at lists.ubuntu.com
>> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/kubuntu-users
>>
>>     
>
>   





More information about the kubuntu-users mailing list