Sort file using unix commands
Clash Royale CLAN TAG#URR8PPP
up vote
-3
down vote
favorite
Input file:
tmp-1064,address3,state,country
tmp-1061,address1,state,country
tmp-1060,address2,state,country
tmp-106,address4,state,country
Current Output file
tmp-1060,address3,state,country
tmp-1061,address1,state,country
tmp-106,address2,state,country
tmp-1064,address4,state,country
Desired Ouptut File
tmp-106,address3,state,country
tmp-1060,address1,state,country
tmp-1061,address2,state,country
tmp-1064,address4,state,country
awk sed sort
 |Â
show 11 more comments
up vote
-3
down vote
favorite
Input file:
tmp-1064,address3,state,country
tmp-1061,address1,state,country
tmp-1060,address2,state,country
tmp-106,address4,state,country
Current Output file
tmp-1060,address3,state,country
tmp-1061,address1,state,country
tmp-106,address2,state,country
tmp-1064,address4,state,country
Desired Ouptut File
tmp-106,address3,state,country
tmp-1060,address1,state,country
tmp-1061,address2,state,country
tmp-1064,address4,state,country
awk sed sort
2
Do you know Google?
â Cyrus
Apr 1 at 18:08
@patrix sort won't work, i want the int value to be compared
â user3303178
Apr 1 at 18:10
2
my example was wrong, see the updated one
â user3303178
Apr 1 at 18:18
2
I suggest you delete the question.
â Cyrus
Apr 1 at 18:26
1
He doesn't need to delete the question(and downvoting it is a bit harsh) but for future reference, it is better that he learns from this that it is important to be clear on what he wants when asking a question to prevent this very thing and get the help he needs.
â Nasir Riley
Apr 1 at 18:28
 |Â
show 11 more comments
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
Input file:
tmp-1064,address3,state,country
tmp-1061,address1,state,country
tmp-1060,address2,state,country
tmp-106,address4,state,country
Current Output file
tmp-1060,address3,state,country
tmp-1061,address1,state,country
tmp-106,address2,state,country
tmp-1064,address4,state,country
Desired Ouptut File
tmp-106,address3,state,country
tmp-1060,address1,state,country
tmp-1061,address2,state,country
tmp-1064,address4,state,country
awk sed sort
Input file:
tmp-1064,address3,state,country
tmp-1061,address1,state,country
tmp-1060,address2,state,country
tmp-106,address4,state,country
Current Output file
tmp-1060,address3,state,country
tmp-1061,address1,state,country
tmp-106,address2,state,country
tmp-1064,address4,state,country
Desired Ouptut File
tmp-106,address3,state,country
tmp-1060,address1,state,country
tmp-1061,address2,state,country
tmp-1064,address4,state,country
awk sed sort
edited Apr 2 at 22:24
asked Apr 1 at 18:06
user3303178
52
52
2
Do you know Google?
â Cyrus
Apr 1 at 18:08
@patrix sort won't work, i want the int value to be compared
â user3303178
Apr 1 at 18:10
2
my example was wrong, see the updated one
â user3303178
Apr 1 at 18:18
2
I suggest you delete the question.
â Cyrus
Apr 1 at 18:26
1
He doesn't need to delete the question(and downvoting it is a bit harsh) but for future reference, it is better that he learns from this that it is important to be clear on what he wants when asking a question to prevent this very thing and get the help he needs.
â Nasir Riley
Apr 1 at 18:28
 |Â
show 11 more comments
2
Do you know Google?
â Cyrus
Apr 1 at 18:08
@patrix sort won't work, i want the int value to be compared
â user3303178
Apr 1 at 18:10
2
my example was wrong, see the updated one
â user3303178
Apr 1 at 18:18
2
I suggest you delete the question.
â Cyrus
Apr 1 at 18:26
1
He doesn't need to delete the question(and downvoting it is a bit harsh) but for future reference, it is better that he learns from this that it is important to be clear on what he wants when asking a question to prevent this very thing and get the help he needs.
â Nasir Riley
Apr 1 at 18:28
2
2
Do you know Google?
â Cyrus
Apr 1 at 18:08
Do you know Google?
â Cyrus
Apr 1 at 18:08
@patrix sort won't work, i want the int value to be compared
â user3303178
Apr 1 at 18:10
@patrix sort won't work, i want the int value to be compared
â user3303178
Apr 1 at 18:10
2
2
my example was wrong, see the updated one
â user3303178
Apr 1 at 18:18
my example was wrong, see the updated one
â user3303178
Apr 1 at 18:18
2
2
I suggest you delete the question.
â Cyrus
Apr 1 at 18:26
I suggest you delete the question.
â Cyrus
Apr 1 at 18:26
1
1
He doesn't need to delete the question(and downvoting it is a bit harsh) but for future reference, it is better that he learns from this that it is important to be clear on what he wants when asking a question to prevent this very thing and get the help he needs.
â Nasir Riley
Apr 1 at 18:28
He doesn't need to delete the question(and downvoting it is a bit harsh) but for future reference, it is better that he learns from this that it is important to be clear on what he wants when asking a question to prevent this very thing and get the help he needs.
â Nasir Riley
Apr 1 at 18:28
 |Â
show 11 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
Tell sort
that your fields are delimited (-t
) by commas and to use the first (-k1) field to sort, but only look at characters 5 and beyond of that field. Add the n
sorting option to sort numerically:
sort -t, -k1.5n input
With GNU sort, you can watch it happen:
$ sort -t, -k1.5n --debug input
sort: using âÂÂen_US.UTF-8â sorting rules
sort: key 1 is numeric and spans multiple fields
tmp-106,address4,state,country
___
______________________________
tmp-1060,address2,state,country
____
_______________________________
tmp-1061,address1,state,country
____
_______________________________
tmp-1064,address3,state,country
____
_______________________________
for me, sort -V worked well.
â user3303178
Apr 9 at 14:22
Great! Feel free to self-answer!
â Jeff Schaller
Apr 9 at 14:30
Cyrus has answered in the Qs' comments!
â user3303178
Apr 9 at 16:47
Comments aren't Answers, unfortunately.
â Jeff Schaller
Apr 9 at 17:06
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Tell sort
that your fields are delimited (-t
) by commas and to use the first (-k1) field to sort, but only look at characters 5 and beyond of that field. Add the n
sorting option to sort numerically:
sort -t, -k1.5n input
With GNU sort, you can watch it happen:
$ sort -t, -k1.5n --debug input
sort: using âÂÂen_US.UTF-8â sorting rules
sort: key 1 is numeric and spans multiple fields
tmp-106,address4,state,country
___
______________________________
tmp-1060,address2,state,country
____
_______________________________
tmp-1061,address1,state,country
____
_______________________________
tmp-1064,address3,state,country
____
_______________________________
for me, sort -V worked well.
â user3303178
Apr 9 at 14:22
Great! Feel free to self-answer!
â Jeff Schaller
Apr 9 at 14:30
Cyrus has answered in the Qs' comments!
â user3303178
Apr 9 at 16:47
Comments aren't Answers, unfortunately.
â Jeff Schaller
Apr 9 at 17:06
add a comment |Â
up vote
1
down vote
Tell sort
that your fields are delimited (-t
) by commas and to use the first (-k1) field to sort, but only look at characters 5 and beyond of that field. Add the n
sorting option to sort numerically:
sort -t, -k1.5n input
With GNU sort, you can watch it happen:
$ sort -t, -k1.5n --debug input
sort: using âÂÂen_US.UTF-8â sorting rules
sort: key 1 is numeric and spans multiple fields
tmp-106,address4,state,country
___
______________________________
tmp-1060,address2,state,country
____
_______________________________
tmp-1061,address1,state,country
____
_______________________________
tmp-1064,address3,state,country
____
_______________________________
for me, sort -V worked well.
â user3303178
Apr 9 at 14:22
Great! Feel free to self-answer!
â Jeff Schaller
Apr 9 at 14:30
Cyrus has answered in the Qs' comments!
â user3303178
Apr 9 at 16:47
Comments aren't Answers, unfortunately.
â Jeff Schaller
Apr 9 at 17:06
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Tell sort
that your fields are delimited (-t
) by commas and to use the first (-k1) field to sort, but only look at characters 5 and beyond of that field. Add the n
sorting option to sort numerically:
sort -t, -k1.5n input
With GNU sort, you can watch it happen:
$ sort -t, -k1.5n --debug input
sort: using âÂÂen_US.UTF-8â sorting rules
sort: key 1 is numeric and spans multiple fields
tmp-106,address4,state,country
___
______________________________
tmp-1060,address2,state,country
____
_______________________________
tmp-1061,address1,state,country
____
_______________________________
tmp-1064,address3,state,country
____
_______________________________
Tell sort
that your fields are delimited (-t
) by commas and to use the first (-k1) field to sort, but only look at characters 5 and beyond of that field. Add the n
sorting option to sort numerically:
sort -t, -k1.5n input
With GNU sort, you can watch it happen:
$ sort -t, -k1.5n --debug input
sort: using âÂÂen_US.UTF-8â sorting rules
sort: key 1 is numeric and spans multiple fields
tmp-106,address4,state,country
___
______________________________
tmp-1060,address2,state,country
____
_______________________________
tmp-1061,address1,state,country
____
_______________________________
tmp-1064,address3,state,country
____
_______________________________
answered Apr 9 at 11:07
Jeff Schaller
31.1k846105
31.1k846105
for me, sort -V worked well.
â user3303178
Apr 9 at 14:22
Great! Feel free to self-answer!
â Jeff Schaller
Apr 9 at 14:30
Cyrus has answered in the Qs' comments!
â user3303178
Apr 9 at 16:47
Comments aren't Answers, unfortunately.
â Jeff Schaller
Apr 9 at 17:06
add a comment |Â
for me, sort -V worked well.
â user3303178
Apr 9 at 14:22
Great! Feel free to self-answer!
â Jeff Schaller
Apr 9 at 14:30
Cyrus has answered in the Qs' comments!
â user3303178
Apr 9 at 16:47
Comments aren't Answers, unfortunately.
â Jeff Schaller
Apr 9 at 17:06
for me, sort -V worked well.
â user3303178
Apr 9 at 14:22
for me, sort -V worked well.
â user3303178
Apr 9 at 14:22
Great! Feel free to self-answer!
â Jeff Schaller
Apr 9 at 14:30
Great! Feel free to self-answer!
â Jeff Schaller
Apr 9 at 14:30
Cyrus has answered in the Qs' comments!
â user3303178
Apr 9 at 16:47
Cyrus has answered in the Qs' comments!
â user3303178
Apr 9 at 16:47
Comments aren't Answers, unfortunately.
â Jeff Schaller
Apr 9 at 17:06
Comments aren't Answers, unfortunately.
â Jeff Schaller
Apr 9 at 17:06
add a comment |Â
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%2f434873%2fsort-file-using-unix-commands%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
2
Do you know Google?
â Cyrus
Apr 1 at 18:08
@patrix sort won't work, i want the int value to be compared
â user3303178
Apr 1 at 18:10
2
my example was wrong, see the updated one
â user3303178
Apr 1 at 18:18
2
I suggest you delete the question.
â Cyrus
Apr 1 at 18:26
1
He doesn't need to delete the question(and downvoting it is a bit harsh) but for future reference, it is better that he learns from this that it is important to be clear on what he wants when asking a question to prevent this very thing and get the help he needs.
â Nasir Riley
Apr 1 at 18:28