0

This is a really stupid question but I can't find an answer anywhere. So I have a command that prints out lines of text like this:

htop
kvantum
alacritty

And I need to check for a line, not a substring

2 Answers 2

1

Use anchors... for example:

grep '^kvantum$' ...
1
  • 1
    With GNU grep, there's also the -x / --line-regexp option which is "like parenthesizing the pattern and then surrounding it with ^ and $" Jul 13, 2021 at 23:53
1

Bot sed and grep utilize regular expressions. If you want to match a plain text string awk can be a good alternative.

$0 in awk is entire line - or more precise record separated by RS which defaults to newline.

awk '$0 == "some line with $ and * and ..."' file

Or by variable:

awk -v find='some line with $ and * and ...' '$0 == find' file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .