0

Assuming file a.txt has:

1a
2b
3c
4d

so

grep "1" a.txt

would return:

1a

and

grep "3" a.txt 

would return:

3c

what if i want to put a criteria file named crit.txt with the following content:

1
3

is there a switch in grep say -cf for criteria file where i could do

grep -cf crit.txt a.txt

that would return:

1a
3c

or is there other tool that does the same thing, and provide me with an example on how to use the tool. The tool should be a one liner command.

1

man grep:

-f FILE, --file=FILE
          Obtain patterns from FILE, one per line. The empty file contains zero patterns, and therefore matches nothing.  (-f is specified by POSIX.)
  • you're the man!! – takajode Jul 9 '13 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.