Closed Captioning Closed captioning available on our YouTube channel

How to use the uniq command: 2-Minute Linux Tips

Network World | Nov 15, 2019

In this Linux tip, learn how to use the uniq command. It’s a command that’s very useful when you want to reduce or summarize information.

Similar
Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the uniq command. It’s a command that’s very useful when you want to reduce or summarize information. Let’s say we want to see who is logged into one of our servers. We can use a command like this, but uniq isn’t adding any value because every line of output from who is going to be unique:
Introduce awk into the mix, we can select just the first column of data and get a list of unique logins:
$ who | awk '{print $1}' | sort | uniq
jdoe
shs
Note that the sorting is still important because uniq will only count as identical lines that are both the same and in succession. Without the sort, you could get output like this:
Now let’s add uniq’s -c (counting) option to get a by-user count of those logins:
That’s your Linux tip for uniq. If you have questions or would like to suggest a topic, please add a comment below. And don’t forget to subscribe to the IDG Tech(talk) channel on YouTube.
If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.
Popular
Featured videos from IDG.tv