LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Concatenate the output to comma delimited (https://www.linuxquestions.org/questions/programming-9/concatenate-the-output-to-comma-delimited-846008/)

hattori.hanzo 11-23-2010 06:33 AM

Concatenate the output to comma delimited
 
I would like to create csv output from an ipcalc calculation.

Code:

[me@host scripts]$ ./ipcalc 192.168.30.40/255.255.255.248
Address:  192.168.30.40        11000000.10101000.00011110.00101 000
Netmask:  255.255.255.248 = 29 11111111.11111111.11111111.11111 000
Wildcard:  0.0.0.7              00000000.00000000.00000000.00000 111
=>
Network:  192.168.30.40/29    11000000.10101000.00011110.00101 000
HostMin:  192.168.30.41        11000000.10101000.00011110.00101 001
HostMax:  192.168.30.46        11000000.10101000.00011110.00101 110
Broadcast: 192.168.30.47        11000000.10101000.00011110.00101 111
Hosts/Net: 6                    Class C, Private Internet

I am using the following to get the data that I need but cannot figure out how to concatenate the output to comma delimited.

Code:

[me@host scripts]$ ./ipcalc 192.168.30.40/255.255.255.248 | awk '{ print $2}' | sed -n '5,7p'
192.168.30.40/29
192.168.30.41
192.168.30.46

Thanks & Regards

Update:

Figured it out :-)

Quote:

[me@host scripts]$ ./ipcalc 192.168.30.40/255.255.255.248 | awk '{ print $2}' | sed -n '5,7p' | tr '\n' ','
192.168.30.40/29,192.168.30.41,192.168.30.46

grail 11-23-2010 07:13 AM

I am pretty sure you could have done it all with your awk command. I am not familiar with ipcalc but if you give me the generated output I can show you how?
ie, output of
Code:

./ipcalc 192.168.30.40/255.255.255.248


All times are GMT -5. The time now is 01:58 PM.