Big fan of stackoverflow. Am a beginner myself and have found a lot of help on this site but have run into problems now.
Today I have a function like the following.
I read a text file (data.txt) for each new line written to it. If the text line contains any word that is included in the Array "pets", it writes that line into another text file pets.txt but ignores the other lines.
How do I invert that function?
I want to be able to block bad words with an Array(badword) so that these are not written to the file petslist.log
pets.filter contains
pets=(
'Dog'
'Cat'
'Mouse'
'Horse'
)
badword.filter contains
badword=(
'Stupid'
'Dumb'
'Bad'
)
script.sh contains
#!/bin/bash
source /home/pi/pets.filter
source /home/pi/badword.filter
while IFS='' read -r line
do
while [ "${pets[count]}" != "" ]
do
if [ "${line/${pets[count]}}" != "$line" ] ; then
echo "$line" >> /logs/petslist.log
fi
count=$(( $count + 1 ))
done
grep -o
solution and concentrated on the line-by-line processing as in the original code (maybe OP wants to do something more than just filtering?). I'll edit the answer – xezo360hye May 28 '23 at 08:10