LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-03-2012, 07:16 AM   #1
MikeHasLinuxQuestions
LQ Newbie
 
Registered: May 2012
Posts: 6

Rep: Reputation: Disabled
Smile Cut, Sort...


Hi Everyone!

Extreme newbie here...

Ok so I figured I would use the cut command to view a list of usernames and login shells from the /etc/passwd file. I wanted to take out the ":" and replace it with a space. Then I wanted to sort the list in ascending order using the login shell column as the primary and the usernames as the secondary. So I tried the following and I'm just scratching my head as to why it is not working exactly the way I want it to.

cut -d: -f1,7 --output-delimiter=" " /etc/passwd | sort -k7 -k1

Everything is working fine except for the sorting. This seems to be sorting the first column but not the second (or the 7th column, the column I want sorted first).

Any ideas Linux gurus?

Thank you!

Mike
 
Old 05-03-2012, 07:20 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

The output created by the cut command has 2 columns, not 7:
Code:
cut -d: -f1,7 --output-delimiter=" " /etc/passwd | sort -k2 -k1
Hope this helps.
 
Old 05-03-2012, 07:28 AM   #3
MikeHasLinuxQuestions
LQ Newbie
 
Registered: May 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi Druuna!

OMG! HA HA HA! Maybe one day I'll learn to get some sleep and not post stupid questions online! Thank you so much! That puts it all into perspective! YOU are awesome!!!

Thanks again!

Mike
 
Old 05-03-2012, 07:36 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
You're welcome

BTW: Can you put up the [SOLVED] tag.
first post -> Thread Tools -> Mark this thread as solved
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] CUT | SORT | UNIQ -D | Line number of original file? mannoj87 Linux - Newbie 13 04-22-2012 09:54 AM
history |tr '\011' ' ' |tr -s " "| cut -d' ' -f3 |sort |uniq -c |sort -nbr |head -n10 alan_ri General 12 12-04-2010 10:01 PM
help with cut command using find. Cut last 8 characters leaving the rest ncsuapex Programming 4 09-16-2009 09:55 PM
cut and sort incompatible doru Linux - Newbie 4 07-13-2009 11:02 AM


All times are GMT -5. The time now is 05:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration