Search code examples
filetclcurly-braces

Working with file containing unmatched braces


I need to modify a file containing several lines with unmatched braces like:

  rmsd {
    atoms {
      atomsFile 
      atomsCol B
      atomsColValue 1
    }

So if I do this:

set fp [open "fpor.conf" r]
set file_data [read $fp]
close $fp
set confFile [split $file_data "\n"]

set inOut [open "us.in" w]

foreach line $inFile {
     if {[lindex $line 0] == "atomsFile"} {
        lappend line "us.pdb"
     }
     puts $inOut "$line"
}
close $inOut

The script fails with the error: unmatched open brace in list. Is there a way to avoid this?


Solution

  • If your intention is to update the file as follows,

    atomsFile us.pdb
    

    then, instead of checking for the list index of presence, check only the word.

    i.e.

    if {[regexp atomsFile $line]} {
        lappend line "us.pdb"
    }