shell - Finding unique values in a data file based on two columns -
this question has answer here:
- awk/unix group by 4 answers
i have file in unix this
name1 text text 123432re text name2 text text 12344qp text name3 text text1 134234ts text name3 text text2 134234ts text
i want find different types of values in 3rd column user names, lets name1
, name2
, name3
.
like below:
name1 1 name2 1 name3 2
how can required result?
if text in columns before 4th column cannot contain spaces, following should gawk
:
gawk '{++vals[$1][$3];} end {for (u in vals) { c = 0; (t in vals[u]) { ++c; }; print u" "c;} }' yourfile
(note, gawk
supports multidimensional arrays, while standard awk
doesn't, same solution won't work standard awk
.)
Comments
Post a Comment