Bash — reversing MD5 output in a text file & sorting

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite












I have a file1.txt with a list of MD5sums and corresponding filenames.



edad74614d6d3fa2252c3d74ff037ac7 wp-blog-header.php
de4edc0df80ba147ebcc26f9e0a8b96f wp-config.php
68070de41736e57f8757648a80b9cbbb wp-admin/upgrade-functions.php
29b6a5c82153f1371e1188ffa7b47619 wp-admin/error_log
55373449cc2320c57803f1f5b52b9ce9 wp-admin/edit.php


How do I dump this to a file2.txt with lines starting with the filenames instead of the hash and sort alphabetically like such:



wp-blog-header.php edad74614d6d3fa2252c3d74ff037ac7
wp-config.php de4edc0df80ba147ebcc26f9e0a8b96f
wp-admin/edit.php 55373449cc2320c57803f1f5b52b9ce9
wp-admin/error_log 29b6a5c82153f1371e1188ffa7b47619
wp-admin/upgrade-functions.php 68070de41736e57f8757648a80b9cbbb


Thank you so, so much!










share|improve this question























  • Sorry about that. Fixed.
    – user9331490
    Feb 9 at 6:42










  • Thanks. So you want to sort only on filenames and not on the whole path? Whole path is easier. Do the paths contain spaces? Is something like wp-admin/foo bar.php possible?
    – muru
    Feb 9 at 6:43










  • The reason of the sorting is so that I can then compare the file2.txt with a file3.txt for non-matching lines for "file change detection". I figure this is more efficient with alphabetical sorting. It's better to have space tolerable code just in case.
    – user9331490
    Feb 9 at 6:52










  • More efficient than alphabetical sorting? But it looks like you want the filenames alphabetically sorted (or lexicographically sorted, rather)
    – muru
    Feb 9 at 7:10







  • 2




    I guess it's better you would post the activity you were going to do compare for file change with X-->Y way instead of going into X-->X1-->Y way.
    – Î±Ò“sнιη
    Feb 9 at 7:11















up vote
1
down vote

favorite












I have a file1.txt with a list of MD5sums and corresponding filenames.



edad74614d6d3fa2252c3d74ff037ac7 wp-blog-header.php
de4edc0df80ba147ebcc26f9e0a8b96f wp-config.php
68070de41736e57f8757648a80b9cbbb wp-admin/upgrade-functions.php
29b6a5c82153f1371e1188ffa7b47619 wp-admin/error_log
55373449cc2320c57803f1f5b52b9ce9 wp-admin/edit.php


How do I dump this to a file2.txt with lines starting with the filenames instead of the hash and sort alphabetically like such:



wp-blog-header.php edad74614d6d3fa2252c3d74ff037ac7
wp-config.php de4edc0df80ba147ebcc26f9e0a8b96f
wp-admin/edit.php 55373449cc2320c57803f1f5b52b9ce9
wp-admin/error_log 29b6a5c82153f1371e1188ffa7b47619
wp-admin/upgrade-functions.php 68070de41736e57f8757648a80b9cbbb


Thank you so, so much!










share|improve this question























  • Sorry about that. Fixed.
    – user9331490
    Feb 9 at 6:42










  • Thanks. So you want to sort only on filenames and not on the whole path? Whole path is easier. Do the paths contain spaces? Is something like wp-admin/foo bar.php possible?
    – muru
    Feb 9 at 6:43










  • The reason of the sorting is so that I can then compare the file2.txt with a file3.txt for non-matching lines for "file change detection". I figure this is more efficient with alphabetical sorting. It's better to have space tolerable code just in case.
    – user9331490
    Feb 9 at 6:52










  • More efficient than alphabetical sorting? But it looks like you want the filenames alphabetically sorted (or lexicographically sorted, rather)
    – muru
    Feb 9 at 7:10







  • 2




    I guess it's better you would post the activity you were going to do compare for file change with X-->Y way instead of going into X-->X1-->Y way.
    – Î±Ò“sнιη
    Feb 9 at 7:11













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have a file1.txt with a list of MD5sums and corresponding filenames.



edad74614d6d3fa2252c3d74ff037ac7 wp-blog-header.php
de4edc0df80ba147ebcc26f9e0a8b96f wp-config.php
68070de41736e57f8757648a80b9cbbb wp-admin/upgrade-functions.php
29b6a5c82153f1371e1188ffa7b47619 wp-admin/error_log
55373449cc2320c57803f1f5b52b9ce9 wp-admin/edit.php


How do I dump this to a file2.txt with lines starting with the filenames instead of the hash and sort alphabetically like such:



wp-blog-header.php edad74614d6d3fa2252c3d74ff037ac7
wp-config.php de4edc0df80ba147ebcc26f9e0a8b96f
wp-admin/edit.php 55373449cc2320c57803f1f5b52b9ce9
wp-admin/error_log 29b6a5c82153f1371e1188ffa7b47619
wp-admin/upgrade-functions.php 68070de41736e57f8757648a80b9cbbb


Thank you so, so much!










share|improve this question















I have a file1.txt with a list of MD5sums and corresponding filenames.



edad74614d6d3fa2252c3d74ff037ac7 wp-blog-header.php
de4edc0df80ba147ebcc26f9e0a8b96f wp-config.php
68070de41736e57f8757648a80b9cbbb wp-admin/upgrade-functions.php
29b6a5c82153f1371e1188ffa7b47619 wp-admin/error_log
55373449cc2320c57803f1f5b52b9ce9 wp-admin/edit.php


How do I dump this to a file2.txt with lines starting with the filenames instead of the hash and sort alphabetically like such:



wp-blog-header.php edad74614d6d3fa2252c3d74ff037ac7
wp-config.php de4edc0df80ba147ebcc26f9e0a8b96f
wp-admin/edit.php 55373449cc2320c57803f1f5b52b9ce9
wp-admin/error_log 29b6a5c82153f1371e1188ffa7b47619
wp-admin/upgrade-functions.php 68070de41736e57f8757648a80b9cbbb


Thank you so, so much!







command-line text-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 9 at 6:42

























asked Feb 9 at 6:35









user9331490

122




122











  • Sorry about that. Fixed.
    – user9331490
    Feb 9 at 6:42










  • Thanks. So you want to sort only on filenames and not on the whole path? Whole path is easier. Do the paths contain spaces? Is something like wp-admin/foo bar.php possible?
    – muru
    Feb 9 at 6:43










  • The reason of the sorting is so that I can then compare the file2.txt with a file3.txt for non-matching lines for "file change detection". I figure this is more efficient with alphabetical sorting. It's better to have space tolerable code just in case.
    – user9331490
    Feb 9 at 6:52










  • More efficient than alphabetical sorting? But it looks like you want the filenames alphabetically sorted (or lexicographically sorted, rather)
    – muru
    Feb 9 at 7:10







  • 2




    I guess it's better you would post the activity you were going to do compare for file change with X-->Y way instead of going into X-->X1-->Y way.
    – Î±Ò“sнιη
    Feb 9 at 7:11

















  • Sorry about that. Fixed.
    – user9331490
    Feb 9 at 6:42










  • Thanks. So you want to sort only on filenames and not on the whole path? Whole path is easier. Do the paths contain spaces? Is something like wp-admin/foo bar.php possible?
    – muru
    Feb 9 at 6:43










  • The reason of the sorting is so that I can then compare the file2.txt with a file3.txt for non-matching lines for "file change detection". I figure this is more efficient with alphabetical sorting. It's better to have space tolerable code just in case.
    – user9331490
    Feb 9 at 6:52










  • More efficient than alphabetical sorting? But it looks like you want the filenames alphabetically sorted (or lexicographically sorted, rather)
    – muru
    Feb 9 at 7:10







  • 2




    I guess it's better you would post the activity you were going to do compare for file change with X-->Y way instead of going into X-->X1-->Y way.
    – Î±Ò“sнιη
    Feb 9 at 7:11
















Sorry about that. Fixed.
– user9331490
Feb 9 at 6:42




Sorry about that. Fixed.
– user9331490
Feb 9 at 6:42












Thanks. So you want to sort only on filenames and not on the whole path? Whole path is easier. Do the paths contain spaces? Is something like wp-admin/foo bar.php possible?
– muru
Feb 9 at 6:43




Thanks. So you want to sort only on filenames and not on the whole path? Whole path is easier. Do the paths contain spaces? Is something like wp-admin/foo bar.php possible?
– muru
Feb 9 at 6:43












The reason of the sorting is so that I can then compare the file2.txt with a file3.txt for non-matching lines for "file change detection". I figure this is more efficient with alphabetical sorting. It's better to have space tolerable code just in case.
– user9331490
Feb 9 at 6:52




The reason of the sorting is so that I can then compare the file2.txt with a file3.txt for non-matching lines for "file change detection". I figure this is more efficient with alphabetical sorting. It's better to have space tolerable code just in case.
– user9331490
Feb 9 at 6:52












More efficient than alphabetical sorting? But it looks like you want the filenames alphabetically sorted (or lexicographically sorted, rather)
– muru
Feb 9 at 7:10





More efficient than alphabetical sorting? But it looks like you want the filenames alphabetically sorted (or lexicographically sorted, rather)
– muru
Feb 9 at 7:10





2




2




I guess it's better you would post the activity you were going to do compare for file change with X-->Y way instead of going into X-->X1-->Y way.
– Î±Ò“sнιη
Feb 9 at 7:11





I guess it's better you would post the activity you were going to do compare for file change with X-->Y way instead of going into X-->X1-->Y way.
– Î±Ò“sнιη
Feb 9 at 7:11











2 Answers
2






active

oldest

votes

















up vote
3
down vote













If your aim is to sort a text file based on specific columns you don't need to change the column order if you use the -k option of GNU sort. To only sort based on the 2nd and subsequent (white-space delimited) columns use:



sort -k 2


Additionally I advise you to use the C or POSIX collation locale to compare and sort path names or you may receive unexpected results due to case-insensitivity or special characters:



LC_COLLATE=POSIX sort ...





share|improve this answer




















  • As you’ve never accepted an answer before: if this answers your question, don’t forget to click the grey ☑ under the number at the left of this text to accept it, which means “yes, this answer is valid”!
    – David Foerster
    Feb 9 at 18:19

















up vote
1
down vote













How about:



awk ' print $2, $1 ' < file | sort > file2


This will take the data from the file called 'file', swap the two fields and sort them into file 'file2'






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    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: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2faskubuntu.com%2fquestions%2f1004468%2fbash-reversing-md5-output-in-a-text-file-sorting%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    If your aim is to sort a text file based on specific columns you don't need to change the column order if you use the -k option of GNU sort. To only sort based on the 2nd and subsequent (white-space delimited) columns use:



    sort -k 2


    Additionally I advise you to use the C or POSIX collation locale to compare and sort path names or you may receive unexpected results due to case-insensitivity or special characters:



    LC_COLLATE=POSIX sort ...





    share|improve this answer




















    • As you’ve never accepted an answer before: if this answers your question, don’t forget to click the grey ☑ under the number at the left of this text to accept it, which means “yes, this answer is valid”!
      – David Foerster
      Feb 9 at 18:19














    up vote
    3
    down vote













    If your aim is to sort a text file based on specific columns you don't need to change the column order if you use the -k option of GNU sort. To only sort based on the 2nd and subsequent (white-space delimited) columns use:



    sort -k 2


    Additionally I advise you to use the C or POSIX collation locale to compare and sort path names or you may receive unexpected results due to case-insensitivity or special characters:



    LC_COLLATE=POSIX sort ...





    share|improve this answer




















    • As you’ve never accepted an answer before: if this answers your question, don’t forget to click the grey ☑ under the number at the left of this text to accept it, which means “yes, this answer is valid”!
      – David Foerster
      Feb 9 at 18:19












    up vote
    3
    down vote










    up vote
    3
    down vote









    If your aim is to sort a text file based on specific columns you don't need to change the column order if you use the -k option of GNU sort. To only sort based on the 2nd and subsequent (white-space delimited) columns use:



    sort -k 2


    Additionally I advise you to use the C or POSIX collation locale to compare and sort path names or you may receive unexpected results due to case-insensitivity or special characters:



    LC_COLLATE=POSIX sort ...





    share|improve this answer












    If your aim is to sort a text file based on specific columns you don't need to change the column order if you use the -k option of GNU sort. To only sort based on the 2nd and subsequent (white-space delimited) columns use:



    sort -k 2


    Additionally I advise you to use the C or POSIX collation locale to compare and sort path names or you may receive unexpected results due to case-insensitivity or special characters:



    LC_COLLATE=POSIX sort ...






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 9 at 18:17









    David Foerster

    26.5k1362106




    26.5k1362106











    • As you’ve never accepted an answer before: if this answers your question, don’t forget to click the grey ☑ under the number at the left of this text to accept it, which means “yes, this answer is valid”!
      – David Foerster
      Feb 9 at 18:19
















    • As you’ve never accepted an answer before: if this answers your question, don’t forget to click the grey ☑ under the number at the left of this text to accept it, which means “yes, this answer is valid”!
      – David Foerster
      Feb 9 at 18:19















    As you’ve never accepted an answer before: if this answers your question, don’t forget to click the grey ☑ under the number at the left of this text to accept it, which means “yes, this answer is valid”!
    – David Foerster
    Feb 9 at 18:19




    As you’ve never accepted an answer before: if this answers your question, don’t forget to click the grey ☑ under the number at the left of this text to accept it, which means “yes, this answer is valid”!
    – David Foerster
    Feb 9 at 18:19












    up vote
    1
    down vote













    How about:



    awk ' print $2, $1 ' < file | sort > file2


    This will take the data from the file called 'file', swap the two fields and sort them into file 'file2'






    share|improve this answer
























      up vote
      1
      down vote













      How about:



      awk ' print $2, $1 ' < file | sort > file2


      This will take the data from the file called 'file', swap the two fields and sort them into file 'file2'






      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        How about:



        awk ' print $2, $1 ' < file | sort > file2


        This will take the data from the file called 'file', swap the two fields and sort them into file 'file2'






        share|improve this answer












        How about:



        awk ' print $2, $1 ' < file | sort > file2


        This will take the data from the file called 'file', swap the two fields and sort them into file 'file2'







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 9 at 19:13









        Colin Ian King

        11.6k13346




        11.6k13346



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1004468%2fbash-reversing-md5-output-in-a-text-file-sorting%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            pylint3 and pip3 broken

            Missing snmpget and snmpwalk

            How to enroll fingerprints to Ubuntu 17.10 with VFS491