Do not confuse this question to be a duplicate of "what is difference b/w sort -u and sort | uniq"
This is in essence a word count program
Confusion raised from the following command is reason for asking this question:
root@sanctum:~/datascience# cat data
this is a file that is supposed to be a file
this gives incorrect output:
root@sanctum:~/datascience# cat data | sed 's/ /\n/g' | uniq -c
1 this
1 is
1 a
1 file
1 that
1 is
1 supposed
1 to
1 be
1 a
1 file
Piping the output to sort and then to uniq gives the perfect answer-
root@sanctum:~/datascience# cat data | sed 's/ /\n/g' | sort |uniq -c
2 a
1 be
2 file
2 is
1 supposed
1 that
1 this
1 to
output of when piped just to sort:
root@sanctum:~/datascience# cat data | sed 's/ /\n/g' | sort
a
a
be
file
file
is
is
supposed
that
this
to
how does the line number of appearance of a line have an effect on the count of the occurrences in the file? i dont know how to phrase it but u get the point
Basically why cant cat data | sed 's/ /\n/g' | uniq -c give the required result?