unix shell script :reverse sorting on last field of file












0















Hi I have below file which I want to be reverse sorted on last column of file
I was trying to reverse sort by awk '{print $15}'|sort -nr : but it gives only last column, however I want all data of that file.
file1 :



dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5



Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51



son_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 16



ndf_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 28



Need output like below:



Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51



ndf_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 28



son_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 16



dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5










share|improve this question









New contributor




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
















  • 1





    Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple as paste -d: file2.txt file1.txt

    – steeldriver
    1 hour ago











  • @stelldriver : no specific requirement about delimiter

    – Pankaj Kalbhor
    1 hour ago











  • @Pankaj -- no no no; open a new question -- don't move the goalposts on this one!

    – Jeff Schaller
    1 min ago
















0















Hi I have below file which I want to be reverse sorted on last column of file
I was trying to reverse sort by awk '{print $15}'|sort -nr : but it gives only last column, however I want all data of that file.
file1 :



dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5



Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51



son_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 16



ndf_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 28



Need output like below:



Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51



ndf_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 28



son_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 16



dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5










share|improve this question









New contributor




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
















  • 1





    Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple as paste -d: file2.txt file1.txt

    – steeldriver
    1 hour ago











  • @stelldriver : no specific requirement about delimiter

    – Pankaj Kalbhor
    1 hour ago











  • @Pankaj -- no no no; open a new question -- don't move the goalposts on this one!

    – Jeff Schaller
    1 min ago














0












0








0


1






Hi I have below file which I want to be reverse sorted on last column of file
I was trying to reverse sort by awk '{print $15}'|sort -nr : but it gives only last column, however I want all data of that file.
file1 :



dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5



Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51



son_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 16



ndf_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 28



Need output like below:



Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51



ndf_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 28



son_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 16



dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5










share|improve this question









New contributor




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












Hi I have below file which I want to be reverse sorted on last column of file
I was trying to reverse sort by awk '{print $15}'|sort -nr : but it gives only last column, however I want all data of that file.
file1 :



dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5



Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51



son_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 16



ndf_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 28



Need output like below:



Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51



ndf_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 28



son_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 16



dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5







shell-script text-processing awk






share|improve this question









New contributor




Pankaj Kalbhor 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




Pankaj Kalbhor 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 2 mins ago







Pankaj Kalbhor













New contributor




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









asked 1 hour ago









Pankaj KalbhorPankaj Kalbhor

12




12




New contributor




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





New contributor





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






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








  • 1





    Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple as paste -d: file2.txt file1.txt

    – steeldriver
    1 hour ago











  • @stelldriver : no specific requirement about delimiter

    – Pankaj Kalbhor
    1 hour ago











  • @Pankaj -- no no no; open a new question -- don't move the goalposts on this one!

    – Jeff Schaller
    1 min ago














  • 1





    Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple as paste -d: file2.txt file1.txt

    – steeldriver
    1 hour ago











  • @stelldriver : no specific requirement about delimiter

    – Pankaj Kalbhor
    1 hour ago











  • @Pankaj -- no no no; open a new question -- don't move the goalposts on this one!

    – Jeff Schaller
    1 min ago








1




1





Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple as paste -d: file2.txt file1.txt

– steeldriver
1 hour ago





Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple as paste -d: file2.txt file1.txt

– steeldriver
1 hour ago













@stelldriver : no specific requirement about delimiter

– Pankaj Kalbhor
1 hour ago





@stelldriver : no specific requirement about delimiter

– Pankaj Kalbhor
1 hour ago













@Pankaj -- no no no; open a new question -- don't move the goalposts on this one!

– Jeff Schaller
1 min ago





@Pankaj -- no no no; open a new question -- don't move the goalposts on this one!

– Jeff Schaller
1 min ago










1 Answer
1






active

oldest

votes


















2














You can use the paste command - for example, to merge the files line-by-line with a colon delimiter:



$ paste -d: file2.txt file1.txt
Fnb_dm__exachange_rollback_character:Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character:Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5


If you need a multi-character delimiter, then that is possible using pr ex.



$ pr -TmJS' :' file2.txt file1.txt
Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5





share|improve this answer
























  • it worked ,thanks a lot,Actully I want this file to be sorted on last field I,e example (51), actually I knw how to sort but for that I have to awk that colum then only I can sort (which will give me only last filed in result)but I want to keep all data on that line also, so how can I achive this?

    – Pankaj Kalbhor
    26 mins ago













  • sorting wasn't one of this question's requirements; I'd suggest that you open a new question with steeldriver's current solution and your further requirements.

    – Jeff Schaller
    4 mins ago











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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Pankaj Kalbhor 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%2f495462%2funix-shell-script-reverse-sorting-on-last-field-of-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can use the paste command - for example, to merge the files line-by-line with a colon delimiter:



$ paste -d: file2.txt file1.txt
Fnb_dm__exachange_rollback_character:Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character:Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5


If you need a multi-character delimiter, then that is possible using pr ex.



$ pr -TmJS' :' file2.txt file1.txt
Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5





share|improve this answer
























  • it worked ,thanks a lot,Actully I want this file to be sorted on last field I,e example (51), actually I knw how to sort but for that I have to awk that colum then only I can sort (which will give me only last filed in result)but I want to keep all data on that line also, so how can I achive this?

    – Pankaj Kalbhor
    26 mins ago













  • sorting wasn't one of this question's requirements; I'd suggest that you open a new question with steeldriver's current solution and your further requirements.

    – Jeff Schaller
    4 mins ago
















2














You can use the paste command - for example, to merge the files line-by-line with a colon delimiter:



$ paste -d: file2.txt file1.txt
Fnb_dm__exachange_rollback_character:Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character:Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5


If you need a multi-character delimiter, then that is possible using pr ex.



$ pr -TmJS' :' file2.txt file1.txt
Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5





share|improve this answer
























  • it worked ,thanks a lot,Actully I want this file to be sorted on last field I,e example (51), actually I knw how to sort but for that I have to awk that colum then only I can sort (which will give me only last filed in result)but I want to keep all data on that line also, so how can I achive this?

    – Pankaj Kalbhor
    26 mins ago













  • sorting wasn't one of this question's requirements; I'd suggest that you open a new question with steeldriver's current solution and your further requirements.

    – Jeff Schaller
    4 mins ago














2












2








2







You can use the paste command - for example, to merge the files line-by-line with a colon delimiter:



$ paste -d: file2.txt file1.txt
Fnb_dm__exachange_rollback_character:Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character:Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5


If you need a multi-character delimiter, then that is possible using pr ex.



$ pr -TmJS' :' file2.txt file1.txt
Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5





share|improve this answer













You can use the paste command - for example, to merge the files line-by-line with a colon delimiter:



$ paste -d: file2.txt file1.txt
Fnb_dm__exachange_rollback_character:Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character:Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5


If you need a multi-character delimiter, then that is possible using pr ex.



$ pr -TmJS' :' file2.txt file1.txt
Fnb_dm__exachange_rollback_character :Start Date: 2019-01-08 04:14:59; End Date: 2019-01-08 04:15:50; Difference in seconds = 51
dnb_exchange_brm_rollback_character :Start Date: 2019-01-08 04:16:57; End Date: 2019-01-08 04:17:02; Difference in seconds = 5






share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









steeldriversteeldriver

35.5k35286




35.5k35286













  • it worked ,thanks a lot,Actully I want this file to be sorted on last field I,e example (51), actually I knw how to sort but for that I have to awk that colum then only I can sort (which will give me only last filed in result)but I want to keep all data on that line also, so how can I achive this?

    – Pankaj Kalbhor
    26 mins ago













  • sorting wasn't one of this question's requirements; I'd suggest that you open a new question with steeldriver's current solution and your further requirements.

    – Jeff Schaller
    4 mins ago



















  • it worked ,thanks a lot,Actully I want this file to be sorted on last field I,e example (51), actually I knw how to sort but for that I have to awk that colum then only I can sort (which will give me only last filed in result)but I want to keep all data on that line also, so how can I achive this?

    – Pankaj Kalbhor
    26 mins ago













  • sorting wasn't one of this question's requirements; I'd suggest that you open a new question with steeldriver's current solution and your further requirements.

    – Jeff Schaller
    4 mins ago

















it worked ,thanks a lot,Actully I want this file to be sorted on last field I,e example (51), actually I knw how to sort but for that I have to awk that colum then only I can sort (which will give me only last filed in result)but I want to keep all data on that line also, so how can I achive this?

– Pankaj Kalbhor
26 mins ago







it worked ,thanks a lot,Actully I want this file to be sorted on last field I,e example (51), actually I knw how to sort but for that I have to awk that colum then only I can sort (which will give me only last filed in result)but I want to keep all data on that line also, so how can I achive this?

– Pankaj Kalbhor
26 mins ago















sorting wasn't one of this question's requirements; I'd suggest that you open a new question with steeldriver's current solution and your further requirements.

– Jeff Schaller
4 mins ago





sorting wasn't one of this question's requirements; I'd suggest that you open a new question with steeldriver's current solution and your further requirements.

– Jeff Schaller
4 mins ago










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










draft saved

draft discarded


















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













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












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
















Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495462%2funix-shell-script-reverse-sorting-on-last-field-of-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Loup dans la culture

How to solve the problem of ntp “Unable to contact time server” from KDE?

ASUS Zenbook UX433/UX333 — Configure Touchpad-embedded numpad on Linux