I am working on a perl based project. I have a device config in the form of a string. I want to replace all the line configuration blocks with some other template using regex.
I have 4 types of line configurations in my device config :-

  1. line vty
  2. line console or line con
  3. line template
  4. line default

So I want to replace the complete block of line configuration with my own set of lines.
Example :-
$config = "enable password xyz
enable secret 4 tnhtc92DXBhelxjYk8LWJrPV36S2i4ntXrpb4RFmfqY
ip classless
ip subnet-zero
no ip domain lookup
line vty 0 4
transport input ssh telnet
exec-timeout 720 0
password cisco
login
line con 0
password cisco
!
line template vty
timestamp
exec-timeout 720 0
!
line template vty
timestramp
line console
exec-timeout 0 0
!
line default
exec-timeout 720 0
!";
Usually after each line config block there is a exclamation mark as a delimiter, but there can be a case when it is just a new line so i need to handle that also.
The approach that I am thinking is check for the word line in the config and check till the ! (exclamation mark as delimiter).
How can I do this ? Please help me out..!!!


Check Solution