문제

I am trying to use grep to print only lines that start with a specific pattern. Here is an example

$SERVER_IP = 2.2.2.2
$SERVER_IP_PORT = 1111
$SERVER_IP_XXX = blablabla

I want grep to print only SERVER_IP = 2.2.2.2 and not the other three lines.

I tried the command below but it did not work

grep -e "^\s*\$SERVER_IP$"

If I try:

grep -e "^\s*\$SERVER_IP"

grep will print all three lines

How can I accomplish this using grep -e or egrep? Thank you

도움이 되었습니까?

해결책

grep -e "^\s*\$SERVER_IP\>"

The \> means "word-boundary", or "place where word characters meet non-word characters."

다른 팁

Use grep -e '^\$SERVER_IP =' to match any line that starts with $SERVER_IP =

If you have awk, you can do:

awk '$1=="$SERVER_IP"' file
$SERVER_IP = 2.2.2.2

The == makes it match only while field 1 is exact $SERVER_IP

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top