0

How do I get only the lines with the strings given by list_of_od_strings.txt file_with_strings_in_lines.xml?

This question is similar to Select lines from text file which have ids listed in another file insofar that I have got a file list_of_od_strings.txt with strings that exist in file_with_strings_in_lines.xml. The lines with one of these strings should be printed. The mentioned question has ids in the first file that consist of only one word.

My case here is different insofar, that in ids.csv ids are given as a combination of two to four strings in a row like 'one two 333 four'.

grep -wFf list_of_id_strings.txt file_with_strings_in_lines.xml

gives me an output, where I see the found strings of list_of_id_strings.txt highlighted. However, the lines without strings of list_of_id_strings.txt in file_with_strings_in_lines.xml also show up. To say, I see the whole list_of_id_strings.txt in the output.

How do I get only the lines with the strings given by list_of_od_strings.txt file_with_strings_in_lines.xml?

  • 1
    Does list_of_id_strings.txt contain an empty line? – steeldriver May 24 '19 at 12:20
  • Yes. ... and I understand. Thanks. – Stefan Bollmann May 24 '19 at 19:35
  • So... did excluding empty line(s) fix the issue? – steeldriver May 24 '19 at 22:10
  • Yes - you answered it in a comment, so I cannot tell you otherwise. – Stefan Bollmann May 25 '19 at 7:01
1

the lines without strings of list_of_id_strings.txt in file_with_strings_in_lines.xml also show up

Based on comments, we deduced that the issue was the complement of Convince grep to output all lines, not just those with matches i.e. that your list_of_id_strings.txt contains at least one null string.

-F
    Match using fixed strings.
    [...] A null string shall match every line.

The solution is to remove any null string(s) from the id file.

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.