2016-04-01 3 views

答えて

4

あなたは、-wオプションを使用して、正確な単語を検索することができます。他の人が述べたように 使用

grep -w string 
1

あなたは細かいマニュアルから、fgrep(またはgrep -F)を使用することができます。

-F 
--fixed-strings 
Interpret the pattern as a list of fixed strings 
(instead of regular expressions), separated by newlines, 
any of which is to be matched. (-F is specified by POSIX.) 
+1

これでも '$ header'と一致します。 –

3

grepため-wを使用しています。また、一重引用符を使用する必要があることにも注意してください。それ以外の場合は、値$headがbashによってこの変数の値に展開されます。

grep -w '$head' file 
#  ^ ^
#  single quotes! 

またsedを使用することができます。

sed -n '/\$head\>/p' file 

ここで重要な部分は、ワード演算子の終わりを述べること\>を使用することです。

$ cat a 
hello $head is header blabla yea 
hello head is $header blabla yea 
$ sed -n '/\$head\>/p' a 
hello $head is header blabla yea 
関連する問題