Read a part of a string and count how many times it appears bellow in bash -
Read a part of a string and count how many times it appears bellow in bash -
i have file this:
userid1,username2,group1,other userid2,username2,group2,other userid3,username3,group1,other userid4,username4,group3,other
what need count how many user in group1
, in group2
, etc.
but problem don't know names of groups. need create variable each time found need grouping , increment +1 each time found grouping all-ready has variable. , using bash.
you using awk:
$ awk -f, '{++a[$3]}end{for(i in a)print a[i], "users in group", i}' file 2 users in grouping group1 1 users in grouping group2 1 users in grouping group3
-f,
sets input field separator comma. 3rd field used key array a
, separate counts kept each group. 1 time file has been processed, value each key reported.
string bash file count
Comments
Post a Comment