Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


a program to count the repeat numbers in the file

a program to count the repeat numbers in the file

a program to count the repeat numbers in the file

I am learning tcl/tk and my first task is to write a program to count the repeat number in the second column of this file with content

January 4000 300 200
February 2000 100 0
March 4000 50 10
April 4000 120 300
May 1000 100 0
June 2000 0 0
July 400 1 1
August 4000 200 100
September 2000 100 200
October 0 0 0

Then the program will write to an output file with content

January 4000 300 200 1
February 2000 100 0 1
March 4000 50 10 2
April 4000 120 300 3
May 1000 100 0 0
June 2000 0 0 2
July 400 1 1 0
August 4000 200 100 4
September 2000 100 200 3
October 0 0 0 0

Notice that the last column has been added and it counts the number in second column (from the left) if they are repeat .
It is difficult for me so I would like to have your help.

RE: a program to count the repeat numbers in the file


Your explanation not covers May and October's 0, so I ignored them for now :

CODE --> Tcl

set fil [open "tpham1002002.txt"]

while {! [eof $fil]} {
set line [gets $fil]
set col2 [lindex $line 1]
if {$col2!=""} {
if {[array get count $col2]==""} { set count($col2) 0 }
incr count($col2)
lappend line $count($col2)
puts $line

close $fil


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close