Reputation: 31
I'm trying to run a search command to lookup strings from file1 and find them in file2. I then want to print ONLY the strings from file1 that are NOT FOUND in file2.
File1 would be something like:
read
write
access
File2 would be:
0xFF88 T write
0xFF87 t xyzwrite
0xFF86 T read
0xFF85 T xyzread
0xFF84 T xyzaccess
So the desired result would be:
access
*** Note, I did add a blank to all of the strings in File1 in order to not include every occurrence of the string which is part of another string.
I've tried:
grep -vf file1 file2
and get results from file2 that are all but the write and read lines, addresses included.
I've tried:
grep -vf file2 file1
and get all of file1 because a whole line of file2 never appears in file1.
I've tried:
diff file1 file2 | grep \^|<
and get all of file1 proceeded with < on each line.
I was told that if I could remove the first 8 characters of each line in file2 then the diff/grep commands would work.
I've also tried findstr (Windows) with various options and again, I can't get it to work.
Also, please note that each file has many more lines than I've shown.
Any ideas?
Upvotes: 3
Views: 426
Reputation: 2821
You probably have to do a loop:
for i in $(cat File1); do
grep -q "\<$i\$" File2 || echo $i
done
This will print out:
access
Upvotes: 1