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
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThis 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
Use anchors... for example:
grep '^kvantum$' ...
-x
/ --line-regexp
option which is "like parenthesizing the pattern and then surrounding it with ^
and $
"
Jul 13, 2021 at 23:53
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