Count number of string occurrences [duplicate]

Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
This question already has an answer here:
Get text-file word occurrence count of all words & print output sorted
6 answers
I've extracted strings I'm interested in from another file and now have a list like this:
StringA
StringB
StringA
StringA
StringB
StringC
StringB
How can I extract the number of occurrences each string has using common command-line tools?
I would like to end up with a list like this:
StringA 3
StringB 3
StringC 1
text-processing command-line scripting
marked as duplicate by Sergiy Kolodyazhnyy, slm⦠Jul 5 at 21:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
3
down vote
favorite
This question already has an answer here:
Get text-file word occurrence count of all words & print output sorted
6 answers
I've extracted strings I'm interested in from another file and now have a list like this:
StringA
StringB
StringA
StringA
StringB
StringC
StringB
How can I extract the number of occurrences each string has using common command-line tools?
I would like to end up with a list like this:
StringA 3
StringB 3
StringC 1
text-processing command-line scripting
marked as duplicate by Sergiy Kolodyazhnyy, slm⦠Jul 5 at 21:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
That is NOTjson.
â ctrl-alt-delor
Jul 5 at 13:45
@ctrl-alt-delor let me quote from above "and I've extracted strings I'm interested in" - I didn't say that the shown snippet is JSON!
â cerr
Jul 5 at 13:52
1
So what am I supposed to do with that information. How is it relevant that it was JSON. May be it could be used to create a different answer, that processes the JSON, so yes put it at the end. But at the beginning, I have to parse that, and realise that it is not relevant. It just adds more effort for the reader.
â ctrl-alt-delor
Jul 5 at 13:55
I was half-tempted to write a pure-Bash solution, but I think that's not what you want, so let's edit away the reference to that particular shell.
â ilkkachu
Jul 5 at 13:58
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
This question already has an answer here:
Get text-file word occurrence count of all words & print output sorted
6 answers
I've extracted strings I'm interested in from another file and now have a list like this:
StringA
StringB
StringA
StringA
StringB
StringC
StringB
How can I extract the number of occurrences each string has using common command-line tools?
I would like to end up with a list like this:
StringA 3
StringB 3
StringC 1
text-processing command-line scripting
This question already has an answer here:
Get text-file word occurrence count of all words & print output sorted
6 answers
I've extracted strings I'm interested in from another file and now have a list like this:
StringA
StringB
StringA
StringA
StringB
StringC
StringB
How can I extract the number of occurrences each string has using common command-line tools?
I would like to end up with a list like this:
StringA 3
StringB 3
StringC 1
This question already has an answer here:
Get text-file word occurrence count of all words & print output sorted
6 answers
text-processing command-line scripting
edited Jul 5 at 20:52
Peter Mortensen
76948
76948
asked Jul 5 at 13:05
cerr
61772236
61772236
marked as duplicate by Sergiy Kolodyazhnyy, slm⦠Jul 5 at 21:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Sergiy Kolodyazhnyy, slm⦠Jul 5 at 21:01
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
That is NOTjson.
â ctrl-alt-delor
Jul 5 at 13:45
@ctrl-alt-delor let me quote from above "and I've extracted strings I'm interested in" - I didn't say that the shown snippet is JSON!
â cerr
Jul 5 at 13:52
1
So what am I supposed to do with that information. How is it relevant that it was JSON. May be it could be used to create a different answer, that processes the JSON, so yes put it at the end. But at the beginning, I have to parse that, and realise that it is not relevant. It just adds more effort for the reader.
â ctrl-alt-delor
Jul 5 at 13:55
I was half-tempted to write a pure-Bash solution, but I think that's not what you want, so let's edit away the reference to that particular shell.
â ilkkachu
Jul 5 at 13:58
add a comment |Â
2
That is NOTjson.
â ctrl-alt-delor
Jul 5 at 13:45
@ctrl-alt-delor let me quote from above "and I've extracted strings I'm interested in" - I didn't say that the shown snippet is JSON!
â cerr
Jul 5 at 13:52
1
So what am I supposed to do with that information. How is it relevant that it was JSON. May be it could be used to create a different answer, that processes the JSON, so yes put it at the end. But at the beginning, I have to parse that, and realise that it is not relevant. It just adds more effort for the reader.
â ctrl-alt-delor
Jul 5 at 13:55
I was half-tempted to write a pure-Bash solution, but I think that's not what you want, so let's edit away the reference to that particular shell.
â ilkkachu
Jul 5 at 13:58
2
2
That is NOT
json.â ctrl-alt-delor
Jul 5 at 13:45
That is NOT
json.â ctrl-alt-delor
Jul 5 at 13:45
@ctrl-alt-delor let me quote from above "and I've extracted strings I'm interested in" - I didn't say that the shown snippet is JSON!
â cerr
Jul 5 at 13:52
@ctrl-alt-delor let me quote from above "and I've extracted strings I'm interested in" - I didn't say that the shown snippet is JSON!
â cerr
Jul 5 at 13:52
1
1
So what am I supposed to do with that information. How is it relevant that it was JSON. May be it could be used to create a different answer, that processes the JSON, so yes put it at the end. But at the beginning, I have to parse that, and realise that it is not relevant. It just adds more effort for the reader.
â ctrl-alt-delor
Jul 5 at 13:55
So what am I supposed to do with that information. How is it relevant that it was JSON. May be it could be used to create a different answer, that processes the JSON, so yes put it at the end. But at the beginning, I have to parse that, and realise that it is not relevant. It just adds more effort for the reader.
â ctrl-alt-delor
Jul 5 at 13:55
I was half-tempted to write a pure-Bash solution, but I think that's not what you want, so let's edit away the reference to that particular shell.
â ilkkachu
Jul 5 at 13:58
I was half-tempted to write a pure-Bash solution, but I think that's not what you want, so let's edit away the reference to that particular shell.
â ilkkachu
Jul 5 at 13:58
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
8
down vote
accepted
Use:
sort file | uniq -c
Looks simple?
That's it!my extraction stuff |sort|uniq -cdoes the trick! Great, Thanks!
â cerr
Jul 5 at 13:13
add a comment |Â
up vote
6
down vote
With GNU datamash:
datamash -s -g1 count 1 <file
The output:
StringA 3
StringB 3
StringC 1
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
Use:
sort file | uniq -c
Looks simple?
That's it!my extraction stuff |sort|uniq -cdoes the trick! Great, Thanks!
â cerr
Jul 5 at 13:13
add a comment |Â
up vote
8
down vote
accepted
Use:
sort file | uniq -c
Looks simple?
That's it!my extraction stuff |sort|uniq -cdoes the trick! Great, Thanks!
â cerr
Jul 5 at 13:13
add a comment |Â
up vote
8
down vote
accepted
up vote
8
down vote
accepted
Use:
sort file | uniq -c
Looks simple?
Use:
sort file | uniq -c
Looks simple?
answered Jul 5 at 13:09
schily
8,53921435
8,53921435
That's it!my extraction stuff |sort|uniq -cdoes the trick! Great, Thanks!
â cerr
Jul 5 at 13:13
add a comment |Â
That's it!my extraction stuff |sort|uniq -cdoes the trick! Great, Thanks!
â cerr
Jul 5 at 13:13
That's it!
my extraction stuff |sort|uniq -c does the trick! Great, Thanks!â cerr
Jul 5 at 13:13
That's it!
my extraction stuff |sort|uniq -c does the trick! Great, Thanks!â cerr
Jul 5 at 13:13
add a comment |Â
up vote
6
down vote
With GNU datamash:
datamash -s -g1 count 1 <file
The output:
StringA 3
StringB 3
StringC 1
add a comment |Â
up vote
6
down vote
With GNU datamash:
datamash -s -g1 count 1 <file
The output:
StringA 3
StringB 3
StringC 1
add a comment |Â
up vote
6
down vote
up vote
6
down vote
With GNU datamash:
datamash -s -g1 count 1 <file
The output:
StringA 3
StringB 3
StringC 1
With GNU datamash:
datamash -s -g1 count 1 <file
The output:
StringA 3
StringB 3
StringC 1
answered Jul 5 at 13:11
RomanPerekhrest
22.4k12144
22.4k12144
add a comment |Â
add a comment |Â
2
That is NOT
json.â ctrl-alt-delor
Jul 5 at 13:45
@ctrl-alt-delor let me quote from above "and I've extracted strings I'm interested in" - I didn't say that the shown snippet is JSON!
â cerr
Jul 5 at 13:52
1
So what am I supposed to do with that information. How is it relevant that it was JSON. May be it could be used to create a different answer, that processes the JSON, so yes put it at the end. But at the beginning, I have to parse that, and realise that it is not relevant. It just adds more effort for the reader.
â ctrl-alt-delor
Jul 5 at 13:55
I was half-tempted to write a pure-Bash solution, but I think that's not what you want, so let's edit away the reference to that particular shell.
â ilkkachu
Jul 5 at 13:58