Practice
Resources
Contests
Online IDE
New
Free Mock
Events New Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
logo
Events
Attend free live masterclass hosted by top tech professionals
New
Scaler
Explore Offerings by SCALER

Basic Shell Commands

Go to Problems

Sort and Uniq command in Unix with example

Sort

Input:

     1	denationalise
     2 gingal
     3 bladdery
     4 asepticism
     5 cringing
     6 chalutzim
     7 fanner
     8 jubbulpore
     9 eidolon
    10 overhasty
Sorting alphabetically ( Flag -k used to select a field for sorting)
cat words.txt | sort -k 2 

Output:

     4	asepticism
     3 bladdery
     6 chalutzim
     5 cringing
     1 denationalise
     9 eidolon
     7 fanner
     2 gingal
     8 jubbulpore
    10 overhasty
Uniq

Filter out repeated lines in a file.

Input:

1
2
2
3
3
3
4
4
4
4
5
5
5
5
5
Select unique lines
cat nums.txt | uniq

Output:

1
2
3
4
5

Select unique lines along with their count using -c (count) flag
cat nums.txt | uniq -c

Output:

   1 1
   2 2
   3 3
   4 4
   5 5

Serious about Learning Scripting ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum.
Shell scripting
Problem Score Companies Time Status
Valid phone number 150
21:58
Lines in a given range 200
28:03
Remove Punctuations 250
12:54
Transform CSV 300
19:13
Excel at your interview with Masterclasses Know More
Certificate included
What will you Learn?
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Graduation Year *
Graduation Year *
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test