Sample Header Ad - 728x90

Shell script to check existence of multiple strings in a file

2 votes
4 answers
4092 views
I have 3 strings A='apples' B='bananas' C='carrots' I want to see if all of these exist in the fruit.txt file. If I'm missing A then add A, B then add B, and so on. This is what I have now if grep -qF "$A | $B | $C" fruit.txt; then echo 'exist' else echo 'does not exist' echo $A $B $C >> fruit.txt fi
Asked by nguye313 (21 rep)
Jun 23, 2020, 09:54 PM
Last activity: Jul 8, 2025, 11:04 PM