Title: Grep exact match with multple strings, no dash
Tags: grep
Question: I have a list of genes like this one saved on a variable:
NT5C1B
NUDT19
PCDHA4
I want to grep all these genes at another list of the same type on a txt. I tried this:
grep -w &quot;^$genes$&quot; list.txt
The problem is that it returns to me genes with a dash - like this one similar to NT5C1B:
NT5C1B-RDH14
However, if I search the gene individually:
grep &quot;^NT5C1B$&quot; list.txt
I'll not obtain the gene with the dash but only:
NT5C1B
Is there any way to do this using grep -w or other command?
Comment: we need to see some text in the `list.txt` also, what is in your `$gene` variable? a single entry or all entries as you pasted in your first code block?

Comment: @WiktorStribiżew I think the question was closed probably too soon... "I'll not obtain the gene with the dash but only:...." I **guess** OP wants to get `Pattern-something` in the result. Also, we didn't see the input text, we don't know if it's `-x` case. Anyway, OP didn't describe the requirement clearly.

Comment: Does this answer your question? [How to make grep only match if the entire line matches?](https://stackoverflow.com/a/4709925/3832970)

Comment: Replace `-w` with `-x`?

Here is the accepted answer: Use -x as it only selects exact matches. -w can match a string if it has non-word constituent characters after the substring. See grep(1) .
Comment for this answer: That's it, thanks! In case there were more colums apart from the gene names like this: `chr1 NT5C1B`. Would it work?
Comment for this answer: And in case I only want to grep the gene name (NT5C1B)?
Comment for this answer: @Swimmingbird It will only return exact matches. So assuming you want "chr1 NT5C1B" returned, then you would need to execute `grep -x "chr1 NT5C1B"`.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:10/16/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<grep>', 'Title': 'Grep exact match with multple strings, no dash', 'ViewCount': 82, 'id': 64389281, 'user_AboutMe': '', 'user_AccountId': 12047536.0, 'user_DisplayName': 'Swimming bird', 'user_Reputation': 59.0, 'user_Views': 26.0, 'user_id': 8811945.0}}