0

I am facing an issue on my windows machine with Cygwin in it.
On one of my machine grep exact string match using $ works:

$ ipconfig /all | grep -A 1 'My Ethernet Server Adapter B52-2$'
   Description . . . . . . . . . . . : My Ethernet Server Adapter B52-2
   Physical Address. . . . . . . . . : ##-##-##-##-##

The grep version on this machine is:

$ grep -V
GNU grep 2.6.3

However the same does not work on my other machine having grep 3.0:

$ ipconfig /all | grep -A 1 'My Ethernet Server Adapter B52-2$'

The grep version on this machine:

$ grep -V
grep (GNU grep) 3.0

If I remove $ from the above command I get the results, but I want the exact string match.
Can someone please help me out here?

Thanks in advance!!

Edit: I have already tried grep -w, grep -o, but could not get the expectced answer

4
  • 1
    My guess is you have trailing whitespaces. Does ipconfig /all | sed -e 's/[[:space:]]*$//' | grep -A 1 'My Ethernet Server Adapter B52-2$' return the expected? Mar 29, 2018 at 6:57
  • Yes it works. But is [[:space:]] version specific? Will it work throughout? Currently it's working on both of my machines, but trying to make it work for others as well. Mar 29, 2018 at 7:02
  • @bhagyeshdudhediya [[:space:]] is a standard regular expression matching a space, tab or other whitespace characters. [[:blank:]] matches only tab and space.
    – Kusalananda
    Mar 29, 2018 at 7:43
  • That has more likely to do with how the CRLF line delimiter handling is done (ipconfig being not a Cygwin command, I'd expect it uses Windows line delimiters are opposed to the standard ones) Mar 29, 2018 at 10:34

1 Answer 1

1

Thanks to Mikael and Kusalananda..
I got the expected result with:

ipconfig /all | sed -e 's/[[:space:]]*$//' | grep -A 1 'My Ethernet Server Adapter B52-2$'

OR

ipconfig /all | sed -e 's/\s*$//' | grep -A 1 'My Ethernet Server Adapter B52-2$'

The output of ipconfig /all had trailing white spaces in it and hence my match did not work, with sed the whitespaces are removed and hence I can grep on the exact string now.
Thanks!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .