Вот скрипт awk
с более обширными тестовыми образцами.
input.1.txt
bridge-domain AAAA
mac
aging
time 3
!
limit
maximum 12
notification both
!
port-down flush disable
! -1
igmp snooping profile igmp-snoop 1
! 1.1
bridge-domain BBBB
mac
aging
time 3
!
limit
maximum 12
notification both
port-down flush disable
! -2
igmp snooping profile igmp-snoop 2
! 2.1
bridge-domain CCC
mac
aging
time 3
!
limit
maximum 12
notification both
port-down flush disable
! -3
igmp snooping profile igmp-snoop 3
! 3.1
input.2.txt
interface Bundle-Ether AAAAA
igmp snooping profile igmp-snoop
dhcp ipv4 snoop profile
static-mac-address 0001
static-mac-address 0002
! AAAA section end
igmp snooping profile igmp-snoop
interface Bundle-Ether BBBB
dhcp ipv4 snoop profile
static-mac-address 0001
static-mac-address 0002
! BBBB section end
igmp snooping profile igmp-snoop
interface Bundle-Ether CCCC
dhcp ipv4 snoop profile
static-mac-address 0001
static-mac-address 0002
! CCCC section end
script.awk
FNR == NR { # read insertion paragraph from file 1
inpSectn = inpSectn $0; # accumlate input lines in inpSectn
if (NR % 6 == 0) { # if 6th line add section to array
sectnArr[++arrCount] = inpSectn; # add inpSectn to ordered array
inpSectn = ""; # reset inpSectn
}
next; # skip further processing till all file 1 is consumed.
}
1 # output current input line.
FNR % 12 == 0 { # every 12th line in file 2
print sectnArr[++arrIdx]; # output section
}
работает:
awk -f script.awk input.2.txt input.1.txt
выход:
bridge-domain AAAA
mac
aging
time 3
!
limit
maximum 12
notification both
!
port-down flush disable
! -1
igmp snooping profile igmp-snoop 1
interface Bundle-Ether AAAAA
igmp snooping profile igmp-snoop
dhcp ipv4 snoop profile
static-mac-address 0001
static-mac-address 0002
! AAAA section end
! 1.1
bridge-domain BBBB
mac
aging
time 3
!
limit
maximum 12
notification both
port-down flush disable
! -2
igmp snooping profile igmp-snoop 2
igmp snooping profile igmp-snoop
interface Bundle-Ether BBBB
dhcp ipv4 snoop profile
static-mac-address 0001
static-mac-address 0002
! BBBB section end
! 2.1
bridge-domain CCC
mac
aging
time 3
!
limit
maximum 12
notification both
port-down flush disable
! -3
igmp snooping profile igmp-snoop 3
igmp snooping profile igmp-snoop
interface Bundle-Ether CCCC
dhcp ipv4 snoop profile
static-mac-address 0001
static-mac-address 0002
! CCCC section end
! 3.1