Sort file using unix commands

The name of the pictureThe name of the pictureThe name of the pictureClash 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






share|improve this question


















  • 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















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






share|improve this question


















  • 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













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






share|improve this question














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








share|improve this question













share|improve this question




share|improve this question








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













  • 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











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
____
_______________________________





share|improve this answer




















  • 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










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
);



);








 

draft saved


draft discarded


















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






























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
____
_______________________________





share|improve this answer




















  • 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














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
____
_______________________________





share|improve this answer




















  • 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












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
____
_______________________________





share|improve this answer












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
____
_______________________________






share|improve this answer












share|improve this answer



share|improve this answer










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
















  • 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












 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?