Use your index file listanome.txt
to make a script to be used by sed
to remove rows:
For a listanome.txt
as below ...
$ cat listanome.txt
ze
jao
juca
... the following sed
transforms into an exclude script for each name in the list:
$ sed 's/^/\//; s/$/\/d/' listanome.txt
/ze/d
/jao/d
/juca/d
So, pass this command sed
to the -f
flag of a new sed
, which will execute that script on all files to be affected, supposedly contained in the caminho
directory:
$ sed --in-place=.bak -f <(sed 's/^/\//; s/$/\/d/' listanome.txt) /caminho/*
This will delete all rows from all files in the caminho
directory containing names of listanome.txt
, making backups with the extension ".bak "for each changed file.
If your requirement changes, change the first sed
according to what you want, for example:
-
To delete all lines identical to the index:
$ sed 's/^/\/^/; s/$/$\/d/' listanome.txt
/^ze$/d
/^jao$/d
/^juca$/d
-
To replace the contents of the string with the "REMOVE" string:
$ sed 's/^/\/^\.\*/; s/$/\.\*$\/REMOVER\/g/' listanome.txt
/^.*ze.*$/REMOVER/g
/^.*jao.*$/REMOVER/g
/^.*juca.*$/REMOVER/g