This works fine for me:
awk '{for(i=1;i<=NF;i++) a[$i]++} END {for(k in a) print k,a[k]}' testfile used 1 this 2 be 1 a 1 for 1 testing 1 file 2 will 1 sample 1 is 1
PS you do not need to set -F" " , because by default it has an empty space.
PS2, do not use cat with programs that can read data themselves, such as awk
You can add sort after the code to sort it.
awk '{for(i=1;i<=NF;i++) a[$i]++} END {for(k in a) print k,a[k]}' testfile | sort -k 2 -n a 1 be 1 for 1 is 1 sample 1 testing 1 used 1 will 1 file 2 this 2
Jotne source share