Skip to main content

Script to search for a particular string in all the files, and delete that line.



#!/bin/bash

grep -rl 'pdhcentral.com' . > recordsa_pdhcentral.txt

for i in `cat recordsa_pdhcentral.txt`; do

FileName=$i;

FileBack=$FileName"_bk";

if [ -f $FileName ]; then

sed 's/.*pdhcentral.*//g' $FileName > $FileBack; mv -f $FileBack $FileName

else

echo $FileName " Doesnt Exists...................!!!!! ";

fi

done



Comments

Jino Joseph said…
This comment has been removed by a blog administrator.
Jino Joseph said…
This can be easily done by the below command.

# find . -type f -exec sed -i.bak 's/.*pdhcentral.*//g' {} \;

Eventhough I am not going to delete the post, because it is my history. :-)