Use a command inside sed
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
The purpose of the command should be replacing any IP in file myfile.txt
with the local ip of the server automatically
example:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/LOCALIP/g' myfile.txt
i want to know if it possible to use command for getting local ip address inside sed
basically i want to replace LOCALIP
in my example with this command
/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1
linux sed
New contributor
add a comment |
up vote
1
down vote
favorite
The purpose of the command should be replacing any IP in file myfile.txt
with the local ip of the server automatically
example:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/LOCALIP/g' myfile.txt
i want to know if it possible to use command for getting local ip address inside sed
basically i want to replace LOCALIP
in my example with this command
/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1
linux sed
New contributor
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
The purpose of the command should be replacing any IP in file myfile.txt
with the local ip of the server automatically
example:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/LOCALIP/g' myfile.txt
i want to know if it possible to use command for getting local ip address inside sed
basically i want to replace LOCALIP
in my example with this command
/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1
linux sed
New contributor
The purpose of the command should be replacing any IP in file myfile.txt
with the local ip of the server automatically
example:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/LOCALIP/g' myfile.txt
i want to know if it possible to use command for getting local ip address inside sed
basically i want to replace LOCALIP
in my example with this command
/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1
linux sed
linux sed
New contributor
New contributor
edited Nov 21 at 14:52
Arcticooling
1
1
New contributor
asked Nov 21 at 14:46
Ali EL KANDOUSSI
54
54
New contributor
New contributor
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
1
down vote
You can use command substitution in double quotes:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/'"$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/g" myfile.txt
In single quotes, this won't work, so end the single quotes before LOCALIP
, use double quotes for the command. This way, we don't accidentally do expansions in the search pattern.
New contributor
Thank you for quick answer, got this error : sed: -e expression #1, char 71: unterminated `s' command
– Ali EL KANDOUSSI
Nov 21 at 14:54
Are you sure the command to get IP is executing correctly? What output do you get with/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)
? Also, try putting anecho
beforesed
to see what sed command is finally run.
– Arcticooling
Nov 21 at 15:02
Got this output with /sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1): 207.154.202.52 10.19.0.6
– Ali EL KANDOUSSI
Nov 21 at 15:12
@JeffSchaller but"$(...)"/g
and"$(...)/g"
should both give the same string, shouldn't it?
– Arcticooling
Nov 21 at 15:27
1
Appears the OP has a space - separated list of two IP's coming back from that command, causing the sed command to end early.
– Jeff Schaller
Nov 21 at 16:12
|
show 1 more comment
up vote
0
down vote
Below command worked fine for me
sed "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/"
add a comment |
up vote
0
down vote
accepted
i solved my issue with this command
sed -i "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk 'print $2')/" myfile.txt
New contributor
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
You can use command substitution in double quotes:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/'"$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/g" myfile.txt
In single quotes, this won't work, so end the single quotes before LOCALIP
, use double quotes for the command. This way, we don't accidentally do expansions in the search pattern.
New contributor
Thank you for quick answer, got this error : sed: -e expression #1, char 71: unterminated `s' command
– Ali EL KANDOUSSI
Nov 21 at 14:54
Are you sure the command to get IP is executing correctly? What output do you get with/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)
? Also, try putting anecho
beforesed
to see what sed command is finally run.
– Arcticooling
Nov 21 at 15:02
Got this output with /sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1): 207.154.202.52 10.19.0.6
– Ali EL KANDOUSSI
Nov 21 at 15:12
@JeffSchaller but"$(...)"/g
and"$(...)/g"
should both give the same string, shouldn't it?
– Arcticooling
Nov 21 at 15:27
1
Appears the OP has a space - separated list of two IP's coming back from that command, causing the sed command to end early.
– Jeff Schaller
Nov 21 at 16:12
|
show 1 more comment
up vote
1
down vote
You can use command substitution in double quotes:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/'"$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/g" myfile.txt
In single quotes, this won't work, so end the single quotes before LOCALIP
, use double quotes for the command. This way, we don't accidentally do expansions in the search pattern.
New contributor
Thank you for quick answer, got this error : sed: -e expression #1, char 71: unterminated `s' command
– Ali EL KANDOUSSI
Nov 21 at 14:54
Are you sure the command to get IP is executing correctly? What output do you get with/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)
? Also, try putting anecho
beforesed
to see what sed command is finally run.
– Arcticooling
Nov 21 at 15:02
Got this output with /sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1): 207.154.202.52 10.19.0.6
– Ali EL KANDOUSSI
Nov 21 at 15:12
@JeffSchaller but"$(...)"/g
and"$(...)/g"
should both give the same string, shouldn't it?
– Arcticooling
Nov 21 at 15:27
1
Appears the OP has a space - separated list of two IP's coming back from that command, causing the sed command to end early.
– Jeff Schaller
Nov 21 at 16:12
|
show 1 more comment
up vote
1
down vote
up vote
1
down vote
You can use command substitution in double quotes:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/'"$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/g" myfile.txt
In single quotes, this won't work, so end the single quotes before LOCALIP
, use double quotes for the command. This way, we don't accidentally do expansions in the search pattern.
New contributor
You can use command substitution in double quotes:
sed -i -e 's/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/'"$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/g" myfile.txt
In single quotes, this won't work, so end the single quotes before LOCALIP
, use double quotes for the command. This way, we don't accidentally do expansions in the search pattern.
New contributor
New contributor
answered Nov 21 at 14:52
Arcticooling
1
1
New contributor
New contributor
Thank you for quick answer, got this error : sed: -e expression #1, char 71: unterminated `s' command
– Ali EL KANDOUSSI
Nov 21 at 14:54
Are you sure the command to get IP is executing correctly? What output do you get with/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)
? Also, try putting anecho
beforesed
to see what sed command is finally run.
– Arcticooling
Nov 21 at 15:02
Got this output with /sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1): 207.154.202.52 10.19.0.6
– Ali EL KANDOUSSI
Nov 21 at 15:12
@JeffSchaller but"$(...)"/g
and"$(...)/g"
should both give the same string, shouldn't it?
– Arcticooling
Nov 21 at 15:27
1
Appears the OP has a space - separated list of two IP's coming back from that command, causing the sed command to end early.
– Jeff Schaller
Nov 21 at 16:12
|
show 1 more comment
Thank you for quick answer, got this error : sed: -e expression #1, char 71: unterminated `s' command
– Ali EL KANDOUSSI
Nov 21 at 14:54
Are you sure the command to get IP is executing correctly? What output do you get with/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)
? Also, try putting anecho
beforesed
to see what sed command is finally run.
– Arcticooling
Nov 21 at 15:02
Got this output with /sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1): 207.154.202.52 10.19.0.6
– Ali EL KANDOUSSI
Nov 21 at 15:12
@JeffSchaller but"$(...)"/g
and"$(...)/g"
should both give the same string, shouldn't it?
– Arcticooling
Nov 21 at 15:27
1
Appears the OP has a space - separated list of two IP's coming back from that command, causing the sed command to end early.
– Jeff Schaller
Nov 21 at 16:12
Thank you for quick answer, got this error : sed: -e expression #1, char 71: unterminated `s' command
– Ali EL KANDOUSSI
Nov 21 at 14:54
Thank you for quick answer, got this error : sed: -e expression #1, char 71: unterminated `s' command
– Ali EL KANDOUSSI
Nov 21 at 14:54
Are you sure the command to get IP is executing correctly? What output do you get with
/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)
? Also, try putting an echo
before sed
to see what sed command is finally run.– Arcticooling
Nov 21 at 15:02
Are you sure the command to get IP is executing correctly? What output do you get with
/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)
? Also, try putting an echo
before sed
to see what sed command is finally run.– Arcticooling
Nov 21 at 15:02
Got this output with /sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1): 207.154.202.52 10.19.0.6
– Ali EL KANDOUSSI
Nov 21 at 15:12
Got this output with /sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1): 207.154.202.52 10.19.0.6
– Ali EL KANDOUSSI
Nov 21 at 15:12
@JeffSchaller but
"$(...)"/g
and "$(...)/g"
should both give the same string, shouldn't it?– Arcticooling
Nov 21 at 15:27
@JeffSchaller but
"$(...)"/g
and "$(...)/g"
should both give the same string, shouldn't it?– Arcticooling
Nov 21 at 15:27
1
1
Appears the OP has a space - separated list of two IP's coming back from that command, causing the sed command to end early.
– Jeff Schaller
Nov 21 at 16:12
Appears the OP has a space - separated list of two IP's coming back from that command, causing the sed command to end early.
– Jeff Schaller
Nov 21 at 16:12
|
show 1 more comment
up vote
0
down vote
Below command worked fine for me
sed "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/"
add a comment |
up vote
0
down vote
Below command worked fine for me
sed "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/"
add a comment |
up vote
0
down vote
up vote
0
down vote
Below command worked fine for me
sed "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/"
Below command worked fine for me
sed "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(/sbin/ip -o -4 addr list eth0 | awk 'print $4' | cut -d/ -f1)/"
edited Nov 21 at 16:11
Jesse_b
11.4k23063
11.4k23063
answered Nov 21 at 15:30
Praveen Kumar BS
1,114138
1,114138
add a comment |
add a comment |
up vote
0
down vote
accepted
i solved my issue with this command
sed -i "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk 'print $2')/" myfile.txt
New contributor
add a comment |
up vote
0
down vote
accepted
i solved my issue with this command
sed -i "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk 'print $2')/" myfile.txt
New contributor
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
i solved my issue with this command
sed -i "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk 'print $2')/" myfile.txt
New contributor
i solved my issue with this command
sed -i "s/[0-9]1,3.[0-9]1,3.[0-9]1,3.[0-9]1,3/$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk 'print $2')/" myfile.txt
New contributor
New contributor
answered Nov 21 at 17:28
Ali EL KANDOUSSI
54
54
New contributor
New contributor
add a comment |
add a comment |
Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.
Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.
Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.
Ali EL KANDOUSSI is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483226%2fuse-a-command-inside-sed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown