oliv66
1
Hi all,
I have a list of IP addresses in a column in a text file name ipaddress.txt
192.168.0.1
192.168.0.2
192.168.0.5
192.168.0.4
192.168.0.5
I would like to convert ipaddress.txt to have the following thing :
192.168.0.1, 192.168.0.2, 192.168.0.3,192.168.0.4,192.168.0.5
I know how to do it with a spreadsheet but it would very useful for me to be able to do it in CLI.
I think I should use sed and awk commands but I haven't find a solution up to now
Your help will be very appreciated.
Regards,
Olivier
vbe
2
xargs<ipaddress.txt>new_ipaddress.txt
e.g.
lo4:/export/home/vbe/.test $ cat titi
192.168.0.1
192.168.0.2
192.168.0.5
192.168.0.4
192.168.0.5
lo4:/export/home/vbe/.test $ xargs<titi
192.168.0.1 192.168.0.2 192.168.0.5 192.168.0.4 192.168.0.5
lo4:/export/home/vbe/.test $
one way:
awk '1' ORS=, myFile| sed 's/,$/\n/'
or
xargs < myFile | sed 's/ /,/g'
1 Like
vbe
4
Thanks vgersh99, I missed the commas separated ( dificult to do 2 things at a time...)
1 Like
oliv66
5
many thanks to both of you for your quick response. you have the right answer for my issue.