Reputation: 35
I have a switch configuration with me in config.txt file .I have opened this file into tcl with set fd [open config.txt r]
and and o/p of puts $fd
,
switchport
switchport access vlan 333
switchport mode access
switchport port-security
switchport port-security maximum 5
Now I want to parse this o/p to another file called newconfig.txt and it should look like following,
switchport
switchport access vlan 333
switchport mode access
switchport port-security
switchport port-security maximum 5
Can anybody tell me how to this as this file is very large and I want to make more readable.
Thanks in advance
Upvotes: 0
Views: 213
Reputation: 398
I think alternative way may be:
set in [open config.txt]
set out [open newconfig.txt w]
set data [read $in]
puts $out [join [split $data "\n"] "\n\n"]
close $in
close $out
This will not add extra new line to the last line in the file :)
Upvotes: 0
Reputation: 55473
If I understood correctly, you want the resulting file to contain all lines from the source file separated by blank lines. This can be done by just appending an extra newline character (\n
) to each line from the source file and writing it out to the resulting file, like this:
set in [open config.txt]
set out [open newconfig.txt w]
while {[gets $in line] >= 0} {
append line \n
puts $out $line
}
close $in
close $out
Upvotes: 2