grep/sed/awk - find match, then match on next line
I'm trying to find the right combination of syntax to match first the hme0 and then the 192.168.* from the output of ifconfig -a shown below. It looks like GNU grep has the -A switch but I don't have GNU grep, I have to use the existing tools on a Solaris 10 machine. I've been playing around with sed and awk, but can't get the right combination.
Code:
# ifconfig -a Code:
if [ "$BASH" ]; then Thanks, Gary |
Do you want just the IP address returned?
Code:
$ sed -n '/hme0: /,/inet/{ I used the sed from cygwin to test it. You might want to check if you need to use "\{1,3\}" or {1,3} for your version of sed. The file "test" I just cut and pasted from your post to test the sed command. |
Code:
ifconfig -a | awk '/^hme0: / {nextline=NR+1;next} |
Thanks jschiwal and ghostdog74. I couldn't get the first one to work. In cygwin I get an error sed: -e expression #1, char 85: unterminated `s' command and on Solaris I get a message about the command being garbled. Nonetheless it will be a good educational example to work through what it does and get it working. The second one works and that looks easy enough to put in my command as well as being educational too.
Thanks again for responding. |
All times are GMT -5. The time now is 11:54 PM. |