0

I am trying to make a script that greps the eth0 ip address and put it the 6th line in a specific file.

I have tried this

newip= $(ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
sed -i 6s/.*/$newip/ file.txt

But this doesn't work, it writes an empty line What am I doing wrong ?

Thank you

0

First try didn't worked for you because of space between equal sign = and variable definition.

| improve this answer | |
0

seems that the newip variable should be this way

newip=$(ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | cut -d: -f 2)
sed -i 6s/.*/$newip/ file.txt

this way it works perfectly, first awk then cut

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.