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?


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

Output should look like this: hq1.abc.com hq2.abc.com
  • You write that you want "output on same line", yet your desired output has two lines. Commented Jul 2, 2018 at 12:55

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .