-   Programming (
-   -   Help to remove script data from file using grep & sed (

djlane 07-13-2010 07:45 AM

Help to remove script data from file using grep & sed
On one of my servers, it appears that a bunch of html files got the following code added to it...


<script src=''></script></body></HTML>
I was going to try to remove this line using grep & sed... as sample
grep -lr -e 'apples' *.html | xargs sed -i 's/apples/oranges/g'

I can get the grep portion to work...

grep "<script src='http:\/\/\/E\/J.JS'[>][<]\/script[>]" *
But not the sed

Any help would be appreciated... I will also make sure that the security right on that directory is changed - so this can't happen again.


David the H. 07-13-2010 08:10 AM


sed "/rtbn2/ s|<script src=''></script>||" filename
In sed, you can use about any regular ascii character as the delimiter, not just /, which makes it easier to handle html input. In this case I used |.

I also added the /rtbn2/ address at the beginning, which, while not necessary, should make it a bit more efficient. Only lines containing that string will have the substitution command run on them.

Also have a look at the -i option for editing the files in place, with optional backup creation.

All times are GMT -5. The time now is 10:23 AM.