I am writing a script to read a file and replace some characters which includes unrecognized characters like
"^H^H^H^H^H^H^H^H^H"
Actually this file was generated by redirecting the console output of a telnet session. I want to remove this character. I have to remove “–More—“ from the file.
I gave a try on replacing them using
set fileID [open "bar" r]
set temp [open "temp.txt" w+]
while {[eof $fileID] != 1} {
gets $fileID lineInfo
regsub -all "More" $lineInfo "" lineInfo
regsub -all "--More--" $lineInfo "" lineInfo #This is not working
puts $temp $lineInfo
}
I can remove “More”, but i am not able to remove “–More–“. Can anybody explain this ?
I also tried like
regsub -all "^H^H^H^H^H^H^H^H^H" $lineInfo "" lineInfo #This is also not working
This also not working.
Thanks in advance.
I would recomment to use the
:print:character class in your regex to match all “sensible” characters — refer to there_syntaxmanual page.The resulting call to
regsubshould replace all non-printable characters with empty strings, so we use a negated character class (via^), and so the proper incantation would look like this:As to removing “–More–“” — I have two hypotheses:
regsubis confused treating--More--as a switch as it starts with a dash. This can be easily fixed by passing--toregsubafter all the switches — see the manual page.xxdor a HEX-editor/viewer.