Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to delete first N lines of grep result files

I'm trying to get rid of a hacker issue on some of my wordpress installs.

This guy puts 9 lines of code in the head of multiple files on my server... I'm trying to use grep and sed to solve this.

Im trying:

grep -r -l  "//360cdn.win/c.css" | xargs -0 sed -e '1,9d' < {}

But nothing is happening, if I remove -0 fromxargs, the result of the files found are clean, but they are not overwriting the origin file with thesed` result, can anyone help me with that?

Many thanks!

like image 715
Renan Corrêa Pinto Avatar asked Dec 21 '16 15:12

Renan Corrêa Pinto


1 Answers

You should use --null option in grep command to output a NUL byte or \0 after each filename in the grep output. Also use -i.bak in sed for inline editing of each file:

grep -lR --null '//360cdn.win/c\.css' . | xargs -0 sed -i.bak '1,9d'
like image 124
anubhava Avatar answered Oct 25 '22 00:10

anubhava