linux - Insert the result of a PostgreSQL "select" at the end of every line of a file -


i have file ips in second column

[postgres@hotname]$ cat /tmp/ips.txt 538954 10.20.30.1 130708 10.20.30.2   55300 10.20.30.3 47634 10.20.30.4 

and table name of servers along ip address. if have name of each ip this:

[postgres@hotname]$ awk '{system("psql database -tc \"select b.des_servidor cat_servidores a,ctl_servidores b a.num_ip=\47"$2"\47 , a.idu_servidor = b.idu_servidor\"")}' /tmp/ips.txt testserver1 testserver2 testserver3 testserver4 

how can insert name of server @ end of file ips, , have this:

[postgres@hotname]$ cat /tmp/ips.txt 538954 10.20.30.1 testserver1 130708 10.20.30.2 testserver2 55300 10.20.30.3 testserver3 47634 10.20.30.4 testserver4 

i've been unsuccessfully trying using awk , sed, read somewhere not recommended.

can me?

with 'e' flag in sed

sed -r 's/([^ ]* )(.*)/echo -n \0" " \;psql database -tc "select b.des_servidor cat_servidores a,ctl_servidores b a.num_ip=\\47\2\\47 , a.idu_servidor = b.idu_servidor"/e' /tmp/ips.txt 

Comments