简体   繁体   中英

How would I grep using STDIN as the query pattern, and a file as the subject?

Without trivially saving stdin to a file, can I take the resulting output of stdin, and USE THAT as the pattern to search against a listing in a file?

Try this example: I have a long list.txt of lines containing filenames that I want to know if I currently have in my directory. It's the backwards equivalent of:

ls | grep -F -f  list.txt

My attempt goes as follows:

 grep -F -f  $( ls -1 ) list.txt

But that doesn't work. Is this even possible?

看起来您想使用关键字-/dev/stdin作为原始格式的文件名。

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