Say we have two files: a.txt and b.txt. Each file has multiple lines of text.
How do I write a shell script to check if all of the content of a.txt exists in b.txt?
Thx for the hints guys, i didn't noticed -q will output 0 if successfully matched.
I end up with:
if grep a.txt -q -f b.txt
; then
else
fi
try
grep
Here is a script that will do what what you are describing:
run:
sh SCRIPT.sh a.txt b.txt
Assumptions:
Using grep
You need to write a loop that iterates over each line in a.txt and use grep (or some other means) to see if that line is in b.txt. If you find any instance where it is not in b.txt, then you can provide the answer: not all lines match. If you find no such instances, you can conclude that all lines match.
Capturing the output of grep using backticks would likely be useful:
kind of thing.
If you have specific questions about how to iterate over the contents of a file, you should ask a specific question about that, showing what you tried.