tags:

views:

56

answers:

1

hi

I have the file:

  # more file
  (WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT = 10234))

but when I try to match part of the line (by grep -w) in the file , grep also match the line (inspite this is part of the full line)

 grep -w "(TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT = 10234))" file

 (WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT = 10234))

my question how to match exactly the line in the file

so if I use grep or something else like sed/awk it will be match only the full line?

Lidia

+1  A: 

By returning the whole line, grep is simply showing that is has found the string in that line. If you only want to see the matched text on the command line, you could (for instance) use -o (only matching):

echo $name | grep -o "(WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT = 10234))"

Just to see the result on the CL, omit "echo $name | ".

If you want to capture the exact text in your variable, you could do:

name=`grep -o "(WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT = 10234))" /Users/deveritt/Desktop/test.html`
echo $name
(WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT = 10234))
Dave Everitt
yes I want to capture the exact line
lidia
...or use the second example with the backticks `
Dave Everitt
I've finished editing now! Hope it works for you.
Dave Everitt