How to sort on a field numerically

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I am trying to sort a file called "Team_James" numerically by the last column, and then I would like to save the output as a new file called "file3".



I tried the command sort Team_James | > s3, but I don't know how to do it, and I don't even know what -k is!
I have been looking everywhere on the Internet.



What am I doing wrong?



Here what the output of my command cat Team_James



Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13









share|improve this question









New contributor




Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • try sort -k 4,4n Team_James >file3
    – steve
    Oct 3 at 21:25










  • Hello @Anonymous what is the expected output?
    – Goro
    Oct 3 at 21:25










  • Hello @Goro trying to get the last field into numeric order
    – Anonymous
    Oct 3 at 21:28










  • Sorry @steve but it didn't work. Trying to get the last field in numeric order.
    – Anonymous
    Oct 3 at 21:31







  • 1




    Might you have a player with a middle name listed?
    – Jeff Schaller
    Oct 3 at 21:38














up vote
1
down vote

favorite












I am trying to sort a file called "Team_James" numerically by the last column, and then I would like to save the output as a new file called "file3".



I tried the command sort Team_James | > s3, but I don't know how to do it, and I don't even know what -k is!
I have been looking everywhere on the Internet.



What am I doing wrong?



Here what the output of my command cat Team_James



Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13









share|improve this question









New contributor




Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • try sort -k 4,4n Team_James >file3
    – steve
    Oct 3 at 21:25










  • Hello @Anonymous what is the expected output?
    – Goro
    Oct 3 at 21:25










  • Hello @Goro trying to get the last field into numeric order
    – Anonymous
    Oct 3 at 21:28










  • Sorry @steve but it didn't work. Trying to get the last field in numeric order.
    – Anonymous
    Oct 3 at 21:31







  • 1




    Might you have a player with a middle name listed?
    – Jeff Schaller
    Oct 3 at 21:38












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to sort a file called "Team_James" numerically by the last column, and then I would like to save the output as a new file called "file3".



I tried the command sort Team_James | > s3, but I don't know how to do it, and I don't even know what -k is!
I have been looking everywhere on the Internet.



What am I doing wrong?



Here what the output of my command cat Team_James



Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13









share|improve this question









New contributor




Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am trying to sort a file called "Team_James" numerically by the last column, and then I would like to save the output as a new file called "file3".



I tried the command sort Team_James | > s3, but I don't know how to do it, and I don't even know what -k is!
I have been looking everywhere on the Internet.



What am I doing wrong?



Here what the output of my command cat Team_James



Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13






linux sort






share|improve this question









New contributor




Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Oct 3 at 21:41









Goro

7,23753168




7,23753168






New contributor




Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Oct 3 at 21:21









Anonymous

104




104




New contributor




Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • try sort -k 4,4n Team_James >file3
    – steve
    Oct 3 at 21:25










  • Hello @Anonymous what is the expected output?
    – Goro
    Oct 3 at 21:25










  • Hello @Goro trying to get the last field into numeric order
    – Anonymous
    Oct 3 at 21:28










  • Sorry @steve but it didn't work. Trying to get the last field in numeric order.
    – Anonymous
    Oct 3 at 21:31







  • 1




    Might you have a player with a middle name listed?
    – Jeff Schaller
    Oct 3 at 21:38
















  • try sort -k 4,4n Team_James >file3
    – steve
    Oct 3 at 21:25










  • Hello @Anonymous what is the expected output?
    – Goro
    Oct 3 at 21:25










  • Hello @Goro trying to get the last field into numeric order
    – Anonymous
    Oct 3 at 21:28










  • Sorry @steve but it didn't work. Trying to get the last field in numeric order.
    – Anonymous
    Oct 3 at 21:31







  • 1




    Might you have a player with a middle name listed?
    – Jeff Schaller
    Oct 3 at 21:38















try sort -k 4,4n Team_James >file3
– steve
Oct 3 at 21:25




try sort -k 4,4n Team_James >file3
– steve
Oct 3 at 21:25












Hello @Anonymous what is the expected output?
– Goro
Oct 3 at 21:25




Hello @Anonymous what is the expected output?
– Goro
Oct 3 at 21:25












Hello @Goro trying to get the last field into numeric order
– Anonymous
Oct 3 at 21:28




Hello @Goro trying to get the last field into numeric order
– Anonymous
Oct 3 at 21:28












Sorry @steve but it didn't work. Trying to get the last field in numeric order.
– Anonymous
Oct 3 at 21:31





Sorry @steve but it didn't work. Trying to get the last field in numeric order.
– Anonymous
Oct 3 at 21:31





1




1




Might you have a player with a middle name listed?
– Jeff Schaller
Oct 3 at 21:38




Might you have a player with a middle name listed?
– Jeff Schaller
Oct 3 at 21:38










1 Answer
1






active

oldest

votes

















up vote
6
down vote



accepted










Looking at the table, in column#1 there are spaces between first name and last name. This means, sort will consider the first and last names two separate columns. As a result, the last column of the input table is #5. The command below, assume that all the names provided in column #1 are first/last and there are no middle names.



cat Team_James | sort -s -n -k 5.1 > file3
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13
Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22




-n, --numeric-sort compare according to string numerical value 
-s, --stable stabilize sort by disabling last-resort comparison
-k, --key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of
line). See POS syntax above.





share|improve this answer






















  • Yes, But once I've done that I need to send it to file3
    – Anonymous
    Oct 3 at 21:34











  • @Anonymous what do you mean send it to file3? By email? or save it in a new file called file3? If yo mean save the output as file3 please see the edits. if by email I can revise again ;-)
    – Goro
    Oct 3 at 21:37







  • 1




    Thank you for solving the problem I was stuck at this for a while.
    – Anonymous
    Oct 3 at 21:40










  • You are welcome ;-) see k explaination
    – Goro
    Oct 3 at 21:42











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Anonymous is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473093%2fhow-to-sort-on-a-field-numerically%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
6
down vote



accepted










Looking at the table, in column#1 there are spaces between first name and last name. This means, sort will consider the first and last names two separate columns. As a result, the last column of the input table is #5. The command below, assume that all the names provided in column #1 are first/last and there are no middle names.



cat Team_James | sort -s -n -k 5.1 > file3
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13
Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22




-n, --numeric-sort compare according to string numerical value 
-s, --stable stabilize sort by disabling last-resort comparison
-k, --key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of
line). See POS syntax above.





share|improve this answer






















  • Yes, But once I've done that I need to send it to file3
    – Anonymous
    Oct 3 at 21:34











  • @Anonymous what do you mean send it to file3? By email? or save it in a new file called file3? If yo mean save the output as file3 please see the edits. if by email I can revise again ;-)
    – Goro
    Oct 3 at 21:37







  • 1




    Thank you for solving the problem I was stuck at this for a while.
    – Anonymous
    Oct 3 at 21:40










  • You are welcome ;-) see k explaination
    – Goro
    Oct 3 at 21:42















up vote
6
down vote



accepted










Looking at the table, in column#1 there are spaces between first name and last name. This means, sort will consider the first and last names two separate columns. As a result, the last column of the input table is #5. The command below, assume that all the names provided in column #1 are first/last and there are no middle names.



cat Team_James | sort -s -n -k 5.1 > file3
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13
Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22




-n, --numeric-sort compare according to string numerical value 
-s, --stable stabilize sort by disabling last-resort comparison
-k, --key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of
line). See POS syntax above.





share|improve this answer






















  • Yes, But once I've done that I need to send it to file3
    – Anonymous
    Oct 3 at 21:34











  • @Anonymous what do you mean send it to file3? By email? or save it in a new file called file3? If yo mean save the output as file3 please see the edits. if by email I can revise again ;-)
    – Goro
    Oct 3 at 21:37







  • 1




    Thank you for solving the problem I was stuck at this for a while.
    – Anonymous
    Oct 3 at 21:40










  • You are welcome ;-) see k explaination
    – Goro
    Oct 3 at 21:42













up vote
6
down vote



accepted







up vote
6
down vote



accepted






Looking at the table, in column#1 there are spaces between first name and last name. This means, sort will consider the first and last names two separate columns. As a result, the last column of the input table is #5. The command below, assume that all the names provided in column #1 are first/last and there are no middle names.



cat Team_James | sort -s -n -k 5.1 > file3
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13
Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22




-n, --numeric-sort compare according to string numerical value 
-s, --stable stabilize sort by disabling last-resort comparison
-k, --key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of
line). See POS syntax above.





share|improve this answer














Looking at the table, in column#1 there are spaces between first name and last name. This means, sort will consider the first and last names two separate columns. As a result, the last column of the input table is #5. The command below, assume that all the names provided in column #1 are first/last and there are no middle names.



cat Team_James | sort -s -n -k 5.1 > file3
Jim Roberts 17 728-8295 9
Joyce Murray 7 235-1432 13
Pam Murray 4 657-4324 18
Jim Brown 8 467-8743 22




-n, --numeric-sort compare according to string numerical value 
-s, --stable stabilize sort by disabling last-resort comparison
-k, --key=POS1[,POS2]
start a key at POS1 (origin 1), end it at POS2 (default end of
line). See POS syntax above.






share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 4 at 5:07

























answered Oct 3 at 21:31









Goro

7,23753168




7,23753168











  • Yes, But once I've done that I need to send it to file3
    – Anonymous
    Oct 3 at 21:34











  • @Anonymous what do you mean send it to file3? By email? or save it in a new file called file3? If yo mean save the output as file3 please see the edits. if by email I can revise again ;-)
    – Goro
    Oct 3 at 21:37







  • 1




    Thank you for solving the problem I was stuck at this for a while.
    – Anonymous
    Oct 3 at 21:40










  • You are welcome ;-) see k explaination
    – Goro
    Oct 3 at 21:42

















  • Yes, But once I've done that I need to send it to file3
    – Anonymous
    Oct 3 at 21:34











  • @Anonymous what do you mean send it to file3? By email? or save it in a new file called file3? If yo mean save the output as file3 please see the edits. if by email I can revise again ;-)
    – Goro
    Oct 3 at 21:37







  • 1




    Thank you for solving the problem I was stuck at this for a while.
    – Anonymous
    Oct 3 at 21:40










  • You are welcome ;-) see k explaination
    – Goro
    Oct 3 at 21:42
















Yes, But once I've done that I need to send it to file3
– Anonymous
Oct 3 at 21:34





Yes, But once I've done that I need to send it to file3
– Anonymous
Oct 3 at 21:34













@Anonymous what do you mean send it to file3? By email? or save it in a new file called file3? If yo mean save the output as file3 please see the edits. if by email I can revise again ;-)
– Goro
Oct 3 at 21:37





@Anonymous what do you mean send it to file3? By email? or save it in a new file called file3? If yo mean save the output as file3 please see the edits. if by email I can revise again ;-)
– Goro
Oct 3 at 21:37





1




1




Thank you for solving the problem I was stuck at this for a while.
– Anonymous
Oct 3 at 21:40




Thank you for solving the problem I was stuck at this for a while.
– Anonymous
Oct 3 at 21:40












You are welcome ;-) see k explaination
– Goro
Oct 3 at 21:42





You are welcome ;-) see k explaination
– Goro
Oct 3 at 21:42











Anonymous is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















Anonymous is a new contributor. Be nice, and check out our Code of Conduct.












Anonymous is a new contributor. Be nice, and check out our Code of Conduct.











Anonymous is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473093%2fhow-to-sort-on-a-field-numerically%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)