sort | uniq -c equivalent #1677
-
Is your feature request related to a problem? Please describe. Describe the solution you'd like Describe alternatives you've considered Additional context
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Hi @alperyilmaz , You can achieve this with $ echo -e "a,1\nb,2\na,1" | qsv frequency --no-headers --delimiter '|'
field,value,count
1,"a,1",2
1,"b,2",1
# to get exactly the output you want
$ echo -e "a,1\nb,2\na,1" | qsv frequency --no-headers --delimiter '|' \
| qsv select count,value | qsv behead \
| qsv fmt --quote-never --out-delimiter ' '
2 a,1
1 b,2 |
Beta Was this translation helpful? Give feedback.
-
RTFM :-)-O
|
Beta Was this translation helpful? Give feedback.
-
Moved it to Discussions as its the closest thing we have to a "Fine Manual" 😉 |
Beta Was this translation helpful? Give feedback.
-
Hi @alperyilmaz one tool that I use and find convenient is Miller. My sample input is this
If I run
I get
I use "|" as separator, so long as it is not in the csv file, to have only one field (one field that contains the entire row). I know, I am off-topic, but I am pleased to share a related experience. |
Beta Was this translation helpful? Give feedback.
-
Not as simple as you wanted, certainly what you propose is simpler and I know you specifically said you did not want an SQL solution but nevertheless with SQL it is not that difficult either and it is only one line of code. Suppose file1.csv contains:
Then
giving
|
Beta Was this translation helpful? Give feedback.
-
One other comment. There is an huniq that supports huniq -c and is written in rust which would make it easier to incorporate into qsv or alternately it could be used independently of qsv. https://crates.io/crates/huniq Example run
|
Beta Was this translation helpful? Give feedback.
Hi @alperyilmaz ,
You can achieve this with
qsv frequency
by specifying--no-headers
and a--delimiter
that doesn't occur in the file: