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 Answers1

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.

steeldriver
  • 81,074