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 = (P开发者_JS百科ROTOCOL = 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
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))
精彩评论