Join Lines

Hi

how do I join files like below in script.

Thanks,
Ashan

there are may line like this in the file.

zone name DR_TMP_A_sev1_3eA vsan 200
  pwwn 50:00:09:73:f0:16:35:08
  pwwn c0:50:76:08:6e:dc:00:16

zone name DR_TMP_A_SVR2_3eA vsan 200
  pwwn 50:00:09:73:f0:16:35:08
  pwwn c0:50:76:08:6e:dc:00:00

need out put

zone name DR_TMP_A_sev1_3eA vsan 200 ,   pwwn 50:00:09:73:f0:16:35:08 ,  pwwn c0:50:76:08:6e:dc:00:16
zone name DR_TMP_A_SVR2_3eA vsan 200 ,   pwwn 50:00:09:73:f0:16:35:08 ,  pwwn c0:50:76:08:6e:dc:00:00

Any attempts/ideas/thoughts from your side?

Anyhow, one option:

paste -sd',, \n' file
zone name DR_TMP_A_sev1_3eA vsan 200,  pwwn 50:00:09:73:f0:16:35:08,  pwwn c0:50:76:08:6e:dc:00:16 
zone name DR_TMP_A_SVR2_3eA vsan 200,  pwwn 50:00:09:73:f0:16:35:08,  pwwn c0:50:76:08:6e:dc:00:00

try also:

awk '$1=$1' RS="\n\n" FS="\n" OFS="," infile

Small universal variation:

awk '{$1=$1}1' RS= FS='\n' OFS=, file

--
Note: RS='\n\n' is GNU awk and mawk only... In regular awk RS can only be one character (or empty), if there are more than one, the first one gets picked

1 Like