How to sort on a field numerically

Clash 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
linux sort
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.
 |Â
show 1 more comment
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
linux sort
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.
trysort -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
 |Â
show 1 more comment
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
linux sort
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
linux sort
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.
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.
trysort -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
 |Â
show 1 more comment
trysort -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
 |Â
show 1 more comment
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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.
Anonymous is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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