sed should process after a matching-pattern multiple commands which are given in braces like {cmd1;cmd2;cmd3}. But in the given code below, all commands followed after d(elite) are ignored.
script.sed
s/^\(interface GigabitEthernet0\)$/\1\/0/
/interface GigabitEthernet0\/0$/{
n # process next line = 1st line (after match) to be deleted
d # Should delete '1st line (after match) to be deleted'
n # process next line = 2nd line to be altered
s/2nd line to be altered/2ND LINE AFTER ALTERATION/
n
s/3rd line to be altered/3RD LINE AFTER ALTERATION/
}
input.txt
interface GigabitEthernet0
1st line (after match) to be deleted
2nd line to be altered
3rd line to be altered
4th line stays unchanged
sed -i -f script.sed example.txt
Expected output:
interface GigabitEthernet0/0
2ND LINE AFTER ALTERATION
3RD LINE AFTER ALTERATION
4th line stays unchanged
Effective output:
interface GigabitEthernet0/0
2nd line to be altered
3rd line to be altered
4th line stays unchanged
As seen in the output above, line 1st line (after match) to be deleted has been effectively deleted. But all following lines (2nd, 3rd, 4th) are not substituted.
BTW: Commands like a(ppend) or c(hange) behaves in the same manner; all followed commands are ignored.