I am trying to replace lines between two pattern/string matches using SED see below. I need to delete lines below interface GigabitEthernet0/3
up to inter
The basic answer seems simple to me:
sed -e "/interface GigabitEthernet0\/3/p" \
-e "/interface GigabitEthernet0\/4/p" \
-e "/interface GigabitEthernet0\/3/,/interface GigabitEthernet0\/4/d" "$@"
Print lines matching 'interface GigabitEthernet0/3', and lines containing 'interface GigabitEthernet0/4'; delete the lines between and including the two.
The only possible issue is that if there is 'interface GigabitEthernet0/4' and no preceding 'interface GigabitEthernet0/3', then that line will be doubled up. If that's an actual problem, then go for a more complex script:
sed -e "/interface GigabitEthernet0\/3/,/interface GigabitEthernet0\/4/{
/interface GigabitEthernet0\/3/p
/interface GigabitEthernet0\/4/p
d
}" "$@"
If you're adamant it must be one line, use semicolons, but the result is illegible.