0

command used is :

grep -f <input_file> <dump_file>

Example : Input_file contains following

apple
banana 

dump_file contains

apple
banana
apple_fruit
banana_fruit 

Objective is to return only apple and banana.

  • Thanks for your question. And for the downvoter: Please leave a comment when downvoting. And if it's because of RTFM, please consider this. – RoVo Mar 7 at 8:24
2

You can use -x with grep to have the pattern match the whole line:

grep -xf <input_file> <dump_file>

Example:

$ printf "%s\n" apple apple_banana | grep -x apple
apple
  • 4
    Since the title refers to "exact text", maybe you should be using -F too? – Kusalananda Mar 7 at 6:42
  • ... because try with ap*ple as the pattern. – Kusalananda Mar 7 at 8:44
  • @Kusalananda I got that, but I don't see a need for it with the current examples. – Olorin Mar 8 at 1:04
  • Thanks for the input, – himanshu pandey Mar 12 at 18:40
  • This command is not working over input as file where inside input strings are sequential line by line. – himanshu pandey Mar 12 at 18:42

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.