I would like to have a shell script that searches two files and returns a list of strings:
File A contains just a list of unique alphanumeric strings, one per line, like this:
accc_34343
GH_HF_223232
cwww_34343
jej_222
File B contains a list of SOME of those strings (some times more than once), and a second column of infomation, like this:
accc_34343 dog
accc_34343 cat
jej_222 cat
jej_222 horse
I would like to create a third file that contains a list of the strings from File A that are NOT in File B.
I’ve tried using some loops with grep -v, but that doesn’t work. So, in the above example, the new file would have this as it’s contents:
GH_HF_223232
cwww_34343
Any help is greatly appreciated!
Here’s what you can do:
Explanation:
grep -v: Use-voption togrepto invert the matching-f: Use-foption togrepto specify that the patterns are from file<(awk '{print $1}' file_b): The<(awk '{print $1}' file_b)is to simply extract the first column values fromfile_bwithout using a temp file; the<( ... )syntax is process substitution.file_a: Tellgrepthat the file to be searched isfile_a> file_c: Output to be written tofile_c