Reputation: 2878
I want to read from a text file containing names and I want to check if the names contain the letter a . if so then I want the output to be y else n in out.txt file
inputs
noman
Lily
####################
outputs
y
n
Upvotes: 0
Views: 789
Reputation: 243
> set fp [open "input.txt" "r+"] ; set out [open "output.txt" "w"]
> #loop through warehouse item rel and disconnect
> while { [gets $fp line] >= 0 } {
> puts $out $line ; }
>
> close $fp close $out;
you need to add the conditional line in the above code:
while { [gets $fp line] >= 0 } {
if {[regexp {a} $line]} {
puts $out "y"
} else {
puts $out "n"
}
}
Upvotes: 2
Reputation: 2878
set fp [open "input.txt" "r+"]
set out [open "output.txt" "w"]
#loop through warehouse item rel and disconnect
while { [gets $fp line] >= 0 } {
puts $out $line ;
}
close $fp
close $out;
This works
Upvotes: 0