Would you expect different outputs from these two command chains?
I'm working on a project for a Linux class, we're writing a script to pull stats from a log file. This specific command chain is to get the number of users running MSIE 6.0. I'm wondering why I'm getting different results between these.
# following the professor's steps
cut -f6 $log \
| grep -v 'MSIE 8.0' \
| grep -v 'MSIE 7.0' \
| grep 'MSIE 6.0' \
| cut -d ';' -f2 \
| uniq -c
# returns 169253`
# using grep -o seems like a more efficient solution to me?
cut -f6 $log \
| grep -v 'MSIE 8.0' \
| grep -v 'MSIE 7.0' \
| grep -o 'MSIE 6.0' \
| uniq -c
# returns 169760
If I use grep -o
to get stats about any other browser I get an exact match for the number of entries with that particular browser. I'm just curious why these are different.
Solution 1:
The 2 commands are not synonymous.
The first command reduced the amount of data available to be compared by removing the first part of the input. This has obviously had the net effect of making more lines in the output identical. Because the lines are identical they are only counted once.
I posit that if you replaced uniq -c
with wc -l
the number of lines would increase but would match in both cases.