I have a text file in which command output is copied. I need to parse the text files in separate columns.
I have the below data in a text file port.txt
NAME---SERIALNUMBER------FREE_PORTS
tx1 s4tx999d 0/1, 0/4,0/6
0/9,0/11
tx2 s4tx998f 1/2,0/9,,1/3
0/8,0/11,
1/7
tx3 s4tx997v 0/9
I require the output in the below format
NAME|SERIALNUMBER|FREE_PORTS
tx1|s4tx999d|0/1,0/4,0/6,0/9,0/11
tx2|s4tx998f|1/2,0/9,1/3,0/8,0/11,1/7
tx3|s4tx997v|0/9
I tried to use the below command, but it does not aggregate all free_ports in a single row
cat ports.txt | cut -c1-5 -- For The Name
cat ports.txt | cut -c6-13 -- For SERIALNUMBER
cat ports.txt | cut -14-23 -- For Free ports