0

I have this ansible command that is writing Docker container ip address and hostname to nginx hosts file which is running for more than 1 time.

How can I join two commands and get ouput on same line and also write the ouput on end of file?

shell:

echo -n docker inspect --format '{''{ .NetworkSettings.IPAddress }''}' hq1; echo abc.com >> ../templates/hosts.j2

Output should look like this:

172.2.3.1 hq1.abc.com
172.2.3.2 hq2.abc.com
  • You write that you want "output on same line", yet your desired output has two lines. – William Pursell Jul 2 '18 at 12:55
1

It looks like you just want to append the string abc.com to the end of each line of output from some command.

docker inspect --format '{{ .NetworkSettings.IPAddress }}' hq1 |
sed 's/$/abc.com/' >>../templates/hosts.j2

The sed command simply replaces the end of the line with the string abc.com.

| 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.