Extract strings in a text file using grep
问题 I have file.txt with names one per line as shown below: ABCB8 ABCC12 ABCC3 ABCC4 AHR ALDH4A1 ALDH5A1 .... I want to grep each of these from an input.txt file. Manually i do this one at a time as grep "ABCB8" input.txt > output.txt Could someone help to automatically grep all the strings in file.txt from input.txt and write it to output.txt. 回答1: for line in `cat text.txt`; do grep $line input.txt >> output.txt; done Contents of text.txt : ABCB8 ABCC12 ABCC3 ABCC4 AHR ALDH4A1 ALDH5A1 Edit : A