Use your index file listanome.txt
to make a script to be used by sed
to remove the lines:
To a listanome.txt
as below...
$ cat listanome.txt
ze
jao
juca
...the following sed
turns into an delete script for each name in the list:
$ sed 's/^/\//; s/$/\/d/' listanome.txt
/ze/d
/jao/d
/juca/d
So, pass such a command sed
to the flag -f
of a new sed
, which will execute such a script on all files to be affected, supposedly contained in the directory caminho
:
$ sed --in-place=.bak -f <(sed 's/^/\//; s/$/\/d/' listanome.txt) /caminho/*
This will delete all lines from all files in the directory caminho
containing the names of listanome.txt
, backing up 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 line contents with the string "REMOVE":
$ sed 's/^/\/^\.\*/; s/$/\.\*$\/REMOVER\/g/' listanome.txt
/^.*ze.*$/REMOVER/g
/^.*jao.*$/REMOVER/g
/^.*juca.*$/REMOVER/g
I think this one can work!! Great, let me play and return here :)
– Rafael Galo
It worked perfectly, you rock! VLW!
– Rafael Galo