I\'m attempting to return some data from an API using OkHttpClient in com.squareup.okhttp. I\'ve run into a few errors that i have eventually been able to overcome but i can\'t
Expanding on zhenbo xu's great answer this is what I did to automate things with sed
in EC2.
sudo sed -i -e '/127.0.0.1/ s/\(localhost\)/'$(hostname)' \1/' /etc/hosts
Note that to allow variable expansion the single quotes end and restart around the subshell call.
hostname
is an executable on some Linux systems (but maybe not all, so you can use an environment variable instead,or remove the quotes around the subshell and use static string).
The \1
is sed
magic, it puts the "captured" search string (s/search/replacement/) in the escaped parentheses back into the replacement string.