简体   繁体   中英

How to grep file by another file's line using bash

The file1 store Sentence want to grep,Here 's content file1

.|||anymore .
,|||arguments
,|||atheists
,|||be
,|||because the
.|||because the

The problem is it contain space in some sentence , and the target file2 contain the space too, how can I search all file2 content to know whether file2 has these sentence which in file1 or not

If found it output grep result to anther file(append) ,If no found output a file to keep it

Try this-

while IFS= read -r i; do      #Reading the file line by line and saving lines in $i.
grep "$i" file2 >> output     #Grepping the line in the second file and outputting.
done < file1

Your question needs to be edited to give some more details though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM