Need to delete first N lines of grep result files Need to delete first N lines of grep result files wordpress wordpress

Need to delete first N lines of grep result files


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'


What's wrong with iterating over the files directly¹?

And you might want to add the -i flat to sed so that files are edited in-place

grep -r -l  "//360cdn.win/c.css" | while read fdo   sed -e '1,9d' -i "${f}"done

¹ well, you might get problems if your files contain newlines and the like.but then...if your website contains files with newlines, you probably have other problems anyhow...