Hi all
Hoping you can help me.
I need to write some Expect TCL that will open a file (RSFO0004) and overwrite the characters on the right side of the first row with the characters stored in a variable ($sIDCurValue). The character length in the variable can vary in size from 2-6 characters long.
An example is below:
$sIDCurValue = 1320
Original file values =
HROS003201012080000000065
TROS0032010120800000000650000000000
New file values =
HROS003201012080000001320
TROS0032010120800000000650000000000
My current code for this scenario is below but it is deleting the entire first row. Any help would be much appreciated:
exp_send "cp RSFO0004 RSFO0004.temp\n"
expect -re $prompt
set fTempRSFO0004 [open "RSFO0004.temp" r]
set fRSFO0004 [open "RSFO0004" w]
set sLineNum 0
while {[gets $fTempRSFO0004 sRSOLine] >= 0} {
if {$sLineNum == 0} {
set sRSOLine [string replace $sRSOLine [expr [string length $sRSOLine] - [string length $sIDCurValue]] [string length $sRSOLine] $sIDCurValue]
}
puts $fRSFO0004 $sRSOLine
}
close $fTempRSFO0004
close $fRSFO0004
Hoping you can help me.
I need to write some Expect TCL that will open a file (RSFO0004) and overwrite the characters on the right side of the first row with the characters stored in a variable ($sIDCurValue). The character length in the variable can vary in size from 2-6 characters long.
An example is below:
$sIDCurValue = 1320
Original file values =
HROS003201012080000000065
TROS0032010120800000000650000000000
New file values =
HROS003201012080000001320
TROS0032010120800000000650000000000
My current code for this scenario is below but it is deleting the entire first row. Any help would be much appreciated:
exp_send "cp RSFO0004 RSFO0004.temp\n"
expect -re $prompt
set fTempRSFO0004 [open "RSFO0004.temp" r]
set fRSFO0004 [open "RSFO0004" w]
set sLineNum 0
while {[gets $fTempRSFO0004 sRSOLine] >= 0} {
if {$sLineNum == 0} {
set sRSOLine [string replace $sRSOLine [expr [string length $sRSOLine] - [string length $sIDCurValue]] [string length $sRSOLine] $sIDCurValue]
}
puts $fRSFO0004 $sRSOLine
}
close $fTempRSFO0004
close $fRSFO0004