Greetings,
I have a file: hostnames.txt which has -
# cat hostnames.txt
machine1
machine2
I need the output to be saved to a variable as:
HOSTNAMELIST=machine1,machine2
Please advise.
Thanks,
Chiru
Greetings,
I have a file: hostnames.txt which has -
# cat hostnames.txt
machine1
machine2
I need the output to be saved to a variable as:
HOSTNAMELIST=machine1,machine2
Please advise.
Thanks,
Chiru
Just a fast one
awk '{a=a $0 ","}END{print "HOSTNAMELIST=" a }' hostnames.txt
Thanks Danmero, that works 99% perfect. Only one thing is that - can I not have the ',' at the end?
Thanks again,
Chiru
What about your contribution ?
This is a "fast" line, not clean but will do your job.
awk '{a=a $0 ","}END{print "HOSTNAMELIST=" a }' hostnames.txt | sed 's/.$//'