ezekiel has asked for the wisdom of the Perl Monks concerning the following question:
I have a text file where each line starts with a string such as in this example:
A1234 ... other text here ... A1234 ... other text here ... B1234 ... other text here ... C2133 ... other text here ... C2133 ... other text here ... C2133 ... other text here ...
Now what I want to do is count how many unique strings appear at the start of the line in the file. In the snippet above there are three: A1234, B1234, C2133.
I can do this by writing a script to loop over the rows, extract the string in question with a regular expression, keeping track of those I've seen as keys of a hash, and adding one to the count if I haven't seen it before.
However, this feels like something I should be able to be do as a one liner, but I can't think of how to do it?
Any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Counting lines starting with a unique string
by Aristotle (Chancellor) on Jun 18, 2002 at 05:04 UTC | |
|
Re: Counting lines starting with a unique string
by jmcnamara (Monsignor) on Jun 18, 2002 at 08:03 UTC | |
|
Re: Counting lines starting with a unique string
by thunders (Priest) on Jun 18, 2002 at 05:47 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |