DomainsFeatured DomainsFeatured - 1 year ago 82
Linux Question

Append Variable To Every Line Of Another Variable

I would like to take the following data which is stored in


term 1
term 2
term 3

And append
which contains:


So, it becomes:

term 1,addition
term 2,addition
term 3,addition

The trick is that it has be done using both as variables. I was thinking echo, paste, awk or sed. It could be something like this:

while read line $variable1; do echo "$line,$variable2"; done

I have played around with them but when variables and quoting get involved, I mess it up. Any help is greatly appreciated.

Answer Source

With GNU bash and a here string:

while IFS='' read -r line; do echo "$line,$variable2"; done <<< "$variable1"


term 1,addition
term 2,addition
term 3,addition
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download