wc Displays number of lines, words and character of a file.
wc * Displays number of lines, words and character of every files in the current directory.
| Switch | Description |
|---|---|
| -l | Only for line count |
| -w | Only for word count |
| -c | Only for byte count |
| -m | Only for character count (1 character = 1 byte) |
[user1@localhost ~]$ cat Winner-List.txt | wc
8 24 169
[user1@localhost ~]$ cat Winner-List.txt | wc -l
8
[user1@localhost ~]$ cat Winner-List.txt | wc -m
169
[user1@localhost ~]$ wc *
wc: Desktop: Is a directory
0 0 0 Desktop
wc: Documents: Is a directory
0 0 0 Documents
wc: Downloads: Is a directory
0 0 0 Downloads
4 8 51 file2
1 2 10 file3
wc: Folder: Is a directory
0 0 0 Folder
wc: Music: Is a directory
0 0 0 Music
wc: Pictures: Is a directory
0 0 0 Pictures
wc: Public: Is a directory
0 0 0 Public
wc: Templates: Is a directory
0 0 0 Templates
wc: Videos: Is a directory
0 0 0 Videos
8 24 169 Winner-List.txt
13 34 230 total
[user1@localhost ~]$
sort Display sorted line.
| Switch | Description |
|---|---|
| -r | Performs a reverse (descending) sort |
| -n | Performs a numeric sort |
| -f | Ignores (folds) case of characters in strings |
| -u | (Unique) removes duplicate lines in output |
| -t : | Uses : as a filed separator |
| -k 3 | Display third column by : delimited field |
Example:
sort -t : -k3 -n /etc/passwd Sort the UIDs in ascending order.
sort -t : -k3 -n /etc/passwd | cut -f3 -d: Shows only UIDs in ascending order.
uniq command displays uniq line/entry.
(uniq without argument removes duplicate adjacent lines)
Note:
I recommend using "sort" with "uniq" to get better result. See below examples for more...
| Switch | Description |
|---|---|
| -u | Display non-repeateed entry i.e that occurs only once. |
| -d | Display repeated entry i.e that occurs more than once. |
| -c | Display number of count that something occurs. |
[user1@localhost ~]$ cat Winner-List.txt
Name, Sport, Medal
Amar, Cricket, Bronze
Akbar, Cricket, Silver
Amar, Kabaddi, Silver
Akbar, Kabaddi, Broze
Anthony, Cricket, Gold
Anthony, Kabaddi, Gold
Hello; Hi; Bye
[user1@localhost ~]$ cat Winner-List.txt | cut -sd, -f1 |uniq
Name
Amar
Akbar
Amar
Akbar
Anthony
[user1@localhost ~]$ cat Winner-List.txt | cut -sd, -f1 |sort |uniq
Akbar
Amar
Anthony
Name
[user1@localhost ~]$ cat Winner-List.txt | cut -sd, -f1 |sort |uniq -c
2 Akbar
2 Amar
2 Anthony
1 Name
[user1@localhost ~]$ cat Winner-List.txt | cut -sd, -f1 |sort |uniq -d
Akbar
Amar
Anthony
[user1@localhost ~]$ cat Winner-List.txt | cut -sd, -f1 |sort |uniq -u
Name
[user1@localhost ~]$