Issue
I'm trying to sort the data that I have but unfortunately It's not working as expected.
Data
interface Vlan198
description *****T3*****
no ip redirects
ip address 0.0.0.0/29
no ipv6 redirects
hsrp 198
ip 172.1.71.129
interface Vlan1004
no ip redirects
no ipv6 redirects
interface Vlan184
description **** Reserved for T2 ****
no ip redirects
ip address 1.1.1.1/26
no ipv6 redirects
hsrp 184
ip 1.1.1.2
interface Vlan750
no ip redirects
ip address 2.2.2.2/24
no ipv6 redirects
hsrp 188
ip 2.2.2.3
interface Vlan183
description **** Reserved for T1 ****
no ip redirects
ip address 3.3.3.3/26
no ipv6 redirects
hsrp 183
ip 3.3.3.4
As you can see in above data, I'm trying to print the data horizontally using below command but the data in not printing as expected because some of the paragraph contains 3,4,7 and I want this to follow 7 line sorting or highest line sorting.
Output of Above Data
interface Vlan198, description *****DC-New backup server installation*****, no ip redirects, ip address 172.1.71.130/29, no ipv6 redirects, hsrp 198, ip 172.1.71.129
interface Vlan1004, no ip redirects, no ipv6 redirects,interface Vlan184, description **** Reserved for Tetration Implementation2 ****, no ip redirects, ip address 172.1.122.195/26
no ipv6 redirects, hsrp 184, ip 172.1.122.193,interface Vlan750, no ip redirects, ip address 172.1.113.2/24, no ipv6 redirects
hsrp 188, ip 172.1.113.1,interface Vlan183, description **** Reserved for Tetration Implementation1 ****, no ip redirects, ip address 172.1.122.131/26, no ipv6 redirects
hsrp 183, ip 172.1.122.129,
Command that I'm using
cat test2 | grep -i 'interface\|description\|ip address\|hsrp\|ip' | awk -v RS='[,\n]' '{printf "%s%s",$0,(NR%7?",":"\n")}'
Expected Output
Solution
Using GNU sed
$ sed -Ez 's/\n +/, /g;s/\n\n/\n/g' input_file
interface Vlan198, description *****T3*****, no ip redirects, ip address 0.0.0.0/29, no ipv6 redirects, hsrp 198, ip 172.1.71.129
interface Vlan1004, no ip redirects, no ipv6 redirects
interface Vlan184, description **** Reserved for T2 ****, no ip redirects, ip address 1.1.1.1/26, no ipv6 redirects, hsrp 184, ip 1.1.1.2
interface Vlan750, no ip redirects, ip address 2.2.2.2/24, no ipv6 redirects, hsrp 188, ip 2.2.2.3
interface Vlan183, description **** Reserved for T1 ****, no ip redirects, ip address 3.3.3.3/26, no ipv6 redirects, hsrp 183, ip 3.3.3.4
Answered By - sseLtaH Answer Checked By - Robin (WPSolving Admin)