unix shell script :reverse sorting on last field of file
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
New contributor
add a comment |
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
New contributor
1
Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple aspaste -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
add a comment |
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
New contributor
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
shell-script text-processing awk
New contributor
New contributor
edited 2 mins ago
Pankaj Kalbhor
New contributor
asked 1 hour ago
Pankaj KalbhorPankaj Kalbhor
12
12
New contributor
New contributor
1
Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple aspaste -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
add a comment |
1
Do you specifically need the delimiter to be the two-character string ` :` (space-colon)? if not you could use something as simple aspaste -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
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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.
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
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
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.
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
Required, but never shown
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
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
Required, but never shown
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
Required, but never shown
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
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
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