Filtering Unique Lines

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

The uniq command excludes consecutive duplicate lines. It has a -c option to display a count of the number of occurances of each line.

-using the man pages as necessary, analyze the following command:

history | cut -c 8-100 | cut -d " " -f 1 | sort | uniq -c

  1. Relevant commands, code, scripts, algorithms:

  2. The attempts at a solution (include all code and scripts):

This was the results from running the command. I have no clue what the command is doing and how the it got the results. Could someone please explain what this command is doing?

william.makarevich@socrates:/home/801NANBEA$ history | cut -c 8-100 | cut -d " " -f 1 | sort | uniq -c
2 ~
2 Andy
2 Anne
6 awk
5 cal
25 cat
11 cd
1 chgrp
2 Claudia
27 clear
1 ~clear
1 cls
7 cp
1 cut
2 %D
2 Danny
85 date
1 ~date
1 del
2 Dennis
3 diff
6 echo
1 env
8 exit
2 grep
1 groups
4 head
1 hist
16 history
2 hostname
1 id
2 Jeff
2 Lewis
2 Lisa
1 list
25 ls
51 man
1 ~man
2 Mickey
2 Mini
3 mkdir
1 more
1 msn
2 mv
1 ps
14 pwd
3 q
1 :q
1 Q
1 QQ
4 quit
1 :quit
2 Rex
4 rm
1 rmdir
2 Robert
2 Ruby
1 Sat,
2 Sherelene
4 sort
2 spell
4 tail
2 Tony
1 touch
2 Vermont
14 vi
5 wc
2 which
2 Wilbert
2 william.makarevich@socrates:~$
2 Williams
2 Yoga
2 ZZ

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Colorado Tech University
Colorado Springs, CO, USA
Professor: Matt Hodges
Course # CS146

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Hi.

It might be easier to understand if you build up the command

history | cut -c 8-100 | cut -d " " -f 1 | sort | uniq -c

step by step, and see what differences there are.

First run

history

(this shows the commands the current logged-in user has run)

A pipe (the | character) feeds the output of one command as input to the next command, so...

history | cut -c 8-100

Will "feed" the output of the history command into the cut command.
(if you'd read the man pages as suggested, you'd know how cut works - this takes characters 8 through to 100)

sort will, sort the output of it's input (the output of the cut command - alphabetically.

uniq -c will remove duplicated (on sorted date - the previous command did that), and show the count (-c).