More Filters
Sort and Uniq


Sort

Sort is not really a filter, but is useful when combined with filters. Sort will sort lines of a file either alphabetically or numerically. Sort has a lot of options, but by default it sorts lines alphabetically starting with the first non-blank character of the line.

The format for the sort command is similiar to the other filters.  You can feed it input via a pipe, e.g. "cat file | sort".  Or you can call sort directly and give it a file, e.g. "sort file".

Here are some examples:
> cat sort_data1
aaaa
bbbb
dd
cccccc

> sort sort_data1
aaaa
bbbb
cccccc
dd


> cat sort_data2
aaa bbb dd ccccc

> sort sort_data2
aaa bbb dd ccccc


> cat sort_data3
aardvark
cat
dog
elephant
aardvark
bat
frog
aardvark

> cat sort_data3 | sort
aardvark
aardvark
aardvark
bat
cat
dog
elephant
frog


Uniq

The uniq command is a filter to remove duplicate lines.

The -c option adds a count, and -d only shows duplicate lines.

Here are a couple of examples:
> cat sort_data3 | sort | uniq
aardvark
bat
cat
dog
elephant
frog

> cat sort_data3 | sort | uniq -c
      3 aardvark
      1 bat
      1 cat
      1 dog
      1 elephant
      1 frog

> cat sort_data3 | sort | uniq -d
aardvark


Assignment

Copy the file "lab19.txt" from the home directory of dannelly. E.g.,
     cp /home/ACC.dannellys2/lab19.txt .
That data file is another version of the graduation list that you have been working with.

Write a one line command (not a script file) to print the names of students in the file lab19.txt who did a double option. For example, Ian Anderson was both a CIFS and ACCT student.

By the way, there were four such students:
Anderson, Ian
Carpenter, Timothy
Killebrew, Douglas Dennis
Nelson, Laura Anne