Bash how to append word to end of a line?

How about just using awk:

awk -F= '/address/{gsub(/:/," ");print $2,"eth0"}' file

Demo:

$ cat file
junk line
address=192.168.0.12:80
address=127.0.0.1:25
don not match this line

$ awk -F= '/address/{gsub(/:/," ");print $2,"eth0"}' file
192.168.0.12 80 eth0
127.0.0.1 25 eth0

Or just with sed:

$ sed -n '/address/{s/:/ /g;s/.*=//;s/$/ eth0/p}' file
192.168.0.12 80 eth0
127.0.0.1 80 eth0

You can match $ to append to a line, like:

sed -e 's/$/ eth0/'

EDIT:

To loop over the lines, I'd suggest using a while loop, like:

while read line
do
  # Do your thing with $line
done < <(grep address file.txt | cut -d'=' -f2 | tr ':' ' ' | sed -e 's/$/ eth0')

Tags:

Unix

Bash

Grep

Awk

Sed