Can't get sed to work
I am getting my current IP address like this:
myIP=$(ip addr show dev eth0 | grep "inet " | cut -d" " -f6 | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}') (myIP then = 12.34.567.890) When I try this, it can't find it to delete it out of the file: (line in file = '1 12.34.567.890') sed -i "/$myIP/d" temp.txt # remove my IP for safety When I do this, it finds it and deletes it: myIP="12.34.567.890" sed -i "/$myIP/d" temp.txt # remove my IP for safety Any suggestions? Thanks. |
I would read the IP using system functions instead of parsing command output:
Code:
myIP=$(perl -MSocket -MSys::Hostname -e '@f=gethostbyname hostname(); print inet_ntoa($f[4])') |
Nice example, I didn't even know that perl could be executed that way. Unfortunately, the sed still didn't delete the ip address in temp.txt.
|
Quote:
|
This actually was working. Just an oversight concerning the wrong IP address.
|
All times are GMT -5. The time now is 11:17 PM. |