For example, the pattern file contains:
thepiratebay.org
some-url.com
Basically, lines with these patterns need to be removed from a file. How can I do that? I prefer a method that uses core utils.
For example, the pattern file contains:
thepiratebay.org
some-url.com
Basically, lines with these patterns need to be removed from a file. How can I do that? I prefer a method that uses core utils.
Using grep:
grep -vf pattern-file data-file > new-file
mv new-file data-file
The -v gives lines which do not contain the pattern(s)
The -f specifies a file which contains the pattern(s)
sed can be used for this operation as well.
sed -i '/thepiratebay.org/d;/some-url.com/d' inputfile.txt
d option deletes the line after finding /pattern/. Use, -i.bak for FreeBSD/MacOS.
-i option edits file in-place and overwrites it in one go. -i.bak does the same, but copies the original file to inputfile.txt.bak.