Can I, in few commands, search and replace multiple lines in a file?
I'm trying to replace the 3 failover blocks from dhcp_primary
by the unique failover block from dhcp_secondary
, within dhcp_primary
.
My goal is to copy the dhcpd.conf from a primary dhcp to the secondary (more information here: http://www.madboa.com/geek/dhcp-failover/). The failover work only if the configuration are identical, except the failover block of course; as you can see is the website's example. So I want to copy this file, but keep the failover information from the secondary.
Example dhcp_primary
:
// some lines above
failover peer "A" {
...
}
failover peer "B" {
...
}
failover peer "C" {
...
}
// some lines below
Example dhcp_secondary
:
// some different lines above
failover peer "D" {
...
}
// some different lines below
The expected output have to be:
// some lines above
failover peer "D" {
...
}
// some lines below
I already can extract the failover blocks :
awk '/^failover/,/^}$/' dhcp_a
awk '/^failover/,/^}$/' dhcp_b
But I don't know how to continue.
Thanks in advance.
Edit: more details for my goal.
You can try:
where
a.awk
is:if the files are only of this structure and kind of content
just take header and trailer of dhcp_a and block content of dhcp_b
if file is bigger (content around) use something like /failover/,/}/ as block delimiter in sed but it depend of the real content
This might work for you (GNU sed):