LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sort Command (https://www.linuxquestions.org/questions/linux-newbie-8/sort-command-4175579801/)

PleaseHelpMeUnderstand 05-14-2016 03:57 PM

Sort Command
 
I want to sort the information a file by file size with the file size is in the 5th field from the left.

I have researched man sort but I am still not comprehending how to do this. Please help. Please and thank you

arizonagroovejet 05-14-2016 04:08 PM

What have you tried so far? If I understand what you want to do correctly, you don't need the sort command, you can do it with ls.

PleaseHelpMeUnderstand 05-14-2016 04:10 PM

Quote:

Originally Posted by arizonagroovejet (Post 5545550)
What have you tried so far? If I understand what you want to do correctly, you don't need the sort command, you can do it with ls.

the file is called etclist. So far I tried ls -lSh and I also tried ls -lSh ~/etclist

arizonagroovejet 05-14-2016 04:19 PM

Quote:

Originally Posted by PleaseHelpMeUnderstand (Post 5545551)
the file is called etclist. So far I tried ls -lSh and I also tried ls -lSh ~/etclist

When you post commands and such like, use CODE tags for readability. E.g.
Code:

ls -lSh ~/etclist
Look for the # button when composing your post.

ls isn't going to show you the contents of a file. I didn't understand what you want to do correctly, I pretty much ignored "I want to sort the information a file" part of your post because it didn't make sense to me, I thought you were trying to sort a directory listing, rather than a directory listing that's in a file. I think the -k and -n options of sort are what you want. Maybe this
Code:

sort -k5 -n ~/etclist
It might help if you posted part of the file in question.

PleaseHelpMeUnderstand 05-14-2016 04:22 PM

Quote:

Originally Posted by arizonagroovejet (Post 5545553)
When you post commands and such like, use CODE tags for readability. E.g.
Code:

ls -lSh ~/etclist
Look for the # button when composing your post.

ls isn't going to show you the contents of a file. I didn't understand what you want to do correctly, I pretty much ignored "I want to sort the information a file" part of your post because it didn't make sense to me, I thought you were trying to sort a directory listing, rather than a directory listing that's in a file. I think the -k and -n options of sort are what you want. Maybe this
Code:

sort -k5 -n ~/etclist
It might help if you posted part of the file in question.

lol you're right it didn't make sense now that I've re-read it. This is what I needed. Thank you kindly


All times are GMT -5. The time now is 06:29 AM.