Artificial intelligent assistant

Grep is not retrieving string with space I have a series of headings in a file that have names like this: grep ">scaffold_3" DM_v6.1_unanchoredScaffolds.fasta >scaffold_3 >scaffold_303 >scaffold_31 >scaffold_34 >scaffold_36 >scaffold_37 >scaffold_39 >scaffold_33 >scaffold_300 I would like to select only the first, so I tried: $ grep ">scaffold_3 " file.fasta $ $ grep ">scaffold_3[[:blank:]]" file.fasta $ $ grep ">scaffold_3\t" file.fasta $ $ grep ">scaffold_3\ " file.fasta $ $ grep ">scaffold_3 " file.fasta $ $ grep ">scaffold_3[[:space:]]" file.fasta $ $ grep ">scaffold_3$" file.fasta >scaffold_3 How can I get the exact name but not the synonyms, given that the character after the name might be a space, tab, newline (perhaps from Windows too) and that `[[:space:]]` did not work? Thank you

If you know there's no whitespace after the text, then `grep ">scaffold_3$"` is right.

Or rather use single quotes since `$` is special within double quotes, and if you want to lock the beginning to start of line too, then add `^` or use `grep -x`. So `grep '^>scaffold_3$'` or `grep -x '>scaffold_3'`

(`-x` is `--line-regexp`: force PATTERN to match only whole lines)

If you can have whitespace at the end of the line and want to ignore any, then


grep -e '>scaffold_3[[:space:]]*$'


would match any amount of optional whitespace between the string and the end of line. (And would also accept the match regardless of where in the line it starts.)

Note that if the file can have Windows-style CRLF line endings, then `>scaffold_3$` will _not_ do, the CR at the end won't match the pattern.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy d0174b85535a5b0e6f6611ffe5f97555