This question maybe the duplicate of this question but the problem that I'm facing is not relevant to that answer. I have tried the code what people posted there but I can't achieve what I want. My code:
set line H_Dev: Issue with DELETE funtion in OSPF OC (Input List is missing required key "identifier")
foreach {name value} [string map {( { } ) {} } $line] {
puts "$name $value"
}
above code not working but after I include { }
set line {H_Dev: Issue with DELETE funtion in OSPF OC (Input List is missing required key "identifier")}
its working like this
H_Dev: Issue
with DELETE
funtion in
OSPF OC
Input List
is missing
required key
identifier
but in my script the $line is in list only. how to get the plain text like this
H_Dev: Issue with DELETE funtion in OSPF OC Input List is missing required key identifier
The problem is this line:
Since you've not quoted anything, you are passing many arguments to
set(which would error as it doesn't take that many arguments), or would be except that"identifier")looks like it is a double-quoted word, except it doesn't because of the)after the closing"and that's the cause of the error.The usual fixes are to either double-quote the whole string (with backslashes before any internal double quotes):
or to put the whole lot in braces (which nest, making it very easy):
To get just the words you want, you can use
string mapto remove the unwanted characters,regsub -allto remove the unwanted characters, orregexp -all -inlineto pick out the wanted words.Option one:
Option two:
Option three:
I tend to prefer to pick out the words that I want instead of filtering the characters that I don't want, as that is less surprising with unexpected inputs. Other people disagree with me.