<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Sep 3, 2008 at 10:16 AM, David L. Willson <span dir="ltr"><<a href="mailto:DLWillson@thegeek.nu">DLWillson@thegeek.nu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I'm trying to capture and return only the IP address from a line of text. I can match<br>
it, but something's wrong with the way I'm trying to capture it. Any thoughts?<br>
<br>
dlwillson@aurora:~<br>
$ grep newwave hosts | grep -E --color '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'<br>
<a href="http://69.88.86.210" target="_blank">69.88.86.210</a> newwaveenviro<br>
<br>
^ That line does successfully color the IP address.<br>
<br>
dlwillson@aurora:~<br>
$ grep newwave hosts | sed -e 's/(([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3})/\1/p'<br>
sed: -e expression #1, char 48: invalid reference \1 on `s' command's RHS<br>
dlwillson@aurora:~<br>
$ grep newwave hosts | sed -e 's/(([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3})/\0/p'<br>
<a href="http://69.88.86.210" target="_blank">69.88.86.210</a> newwaveenviro<br>
dlwillson@aurora:~<br>
$ grep newwave hosts | sed -e 's/(([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3})/\1/p'<br>
sed: -e expression #1, char 48: invalid reference \1 on `s' command's RHS<br>
dlwillson@aurora:~<br>
<br>
Huh...<br>
<br></blockquote></div><br>
I don't know why sed wouldn't work but perl should.<br><br>
Try something like<br>
<br>
perl -lne 'print if s/((\d{1,3}\.){3}\d{1,3}).*\ newwaveenviro\ *.*/\1/' /etc/hosts<br>
<br>
-jacob</div>