I need to check for multiple phrases in txt files, and if file contains them in particular line, remove the line from txt fie.
Using inverse grep with file containing phrases that needs to be removed works as a charm.
THE PROBLEM is that I need to search in part of the each line, rather than the whole line.
I need to check only part of the line until 10th comma character. If grep finds phrase after that I want to keep the line, if grep matches before that point I want to remove the line.
I can't figure out how I could use regex alongside phrases file. Any suggestions welcome.
#!/bin/bash
shopt -s globstar
for f in /uploads/txt/original/**/*.txt ; do
grep -i -v -w -f phrase.txt "$f" > tmp
mv tmp $f
done
echo "Finished!"
EDIT
# Rule to set the flag if the line needs to be printed or not
{
ok = 1
# loop upto tenth column
for (i = 1; i <= 10; i++){
# match against each pattern
for (p in PATS) {
if ($i ~ p) {
ok = 0
}
}
}
}
Does this mean that every column is run agains PATS?
Would it be possible to merge 10 columns into one string and then check agains all patterns instead of checking 10 columns against all patterns?