owwow14
1
Hi, I have tab-deliminated data similar to the following:
dot is-big 2
dot is-round 3
dot is-gray 4
cat is-big 3
hot in-summer 5
I want to count the frequency of each individual "unique" value in the 1st column. Thus, the desired output would be as follows:
dot 3
cat 1
hot 1
is there an
awk
that could help me out with this?
Thank you!
$ awk '{A[$1]++}END{for(i in A)print i,A}' file
hot 1
cat 1
dot 3
Hello,
Here is the solution for same.
awk '{a[$1]++;} END{for(i in a) print a" "i}' file_name
Output will be as follows.
1 hot
3 dot
1 cat
Thanks,
R. Singh
try.
cut -f1 -d" " file | uniq -c
3 dot
1 cat
1 hot
or with awk as requested
awk -F" " '{print $1}' tmp1 | uniq -c
3 dot
1 cat
1 hot
---------- Post updated at 02:23 PM ---------- Previous update was at 01:53 PM ----------
RudiC
5
That would work only with the keywords in contiguous lines.
1 Like
yes, thank you,,, there should be
| sort
for non-contiguous keywords.