sluge
sluge

Reputation: 637

Can't grep file correctly

I have a file with very simple syntax:

cat /tmp/test

ARCH=""prtconf -b | awk '/^name:/ {print $2}'

I tried to grep it:

cat /tmp/test | grep "prtconf -b | awk '/^name:/ {print $2"

ARCH=""prtconf -b | awk '/^name:/ {print $2}'

Let's make grep string a little longer, add } to the end:

cat /tmp/test | grep "prtconf -b | awk '/^name:/ {print $2"}

Nothing found

Why when I add } to the end of the line grep stop working?

OS is Solaris 10U11

Upvotes: 1

Views: 92

Answers (1)

Ravi Dhoriya ツ
Ravi Dhoriya ツ

Reputation: 4414

$2 refers to command-line parameter so here it will substitute blank character in a patter. So you'l need to escape $ by slash like \$

cat /tmp/test | grep "prtconf -b | awk '/^name:/ {print \$2}"

Without adding } in your patter it was working because it was matching actual pattern as prtconf -b | awk '/^name:/ {print for your input. But if you add } in your patter then it will try to match prtconf -b | awk '/^name:/ {print } (which isn't there in your file so it won't show output.)

Upvotes: 1

Related Questions