0

I've downloaded some files. I want to find out whether these file names are present in file.txt one by one. I've tried following command but not successful. I want to find out using xargs. ls | xargs grep file.txt How do I do that?

1 Answer 1

0

Though I'm not sure what exactly means your "one by one" but here is

Short ls + grep approach:

ls -1 | grep -wf - file.txt

  • -1 - ls option, lists one file per line

  • -f file - grep option, obtains patterns from file(or STDIN in case of passing - argument), one per line


The same could be written as:

grep -wf <(ls -1) file.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .