I am having some problems using sed on a sunOS 5.10, I am using bash. For some reason the regexp I am trying to build is not working, even though it should.
I am trying to parse some syslog messages and I need to match the first IP address , then replace it with something else. Does anyone have a quick example of a sed line to match and replace an IP address ?
Ok, I just moved the first \( and now \1 is the whole pattern, I can replace it and it works Thanks for your help so far.
Now I need to do something else. I actually need to replace the IP with a hostname. I have a small script that does this but I am not sure how to pass the \1 to my script, inside the sed statement.
But when I try to integrate it into the sed line, I get this:
server:~$ echo "This is an IP: 10.10.2.10" | sed -e "s/\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\)/`res "\1" `/g"
grep: RE error in \<\1\>: number in \[0-9] invalid
This is an IP:
The grep inside "res" does not like the \1, which I kinda understand. Thing is, if I do a simple echo "\1" instead of the res "\1" then it works, the \1 is replaced with the actual IP from the sed statement.
That works but I kinda need to use the \1, the IP address that I matched. The lines I am going to parse will be syslog entries, which contain IP addresses. I just need to tail the syslog, pipe it through the sed statement and replace the IP address with its equivalent hostname (which I get via the small res script).