creating text file with regards to file names












0















I have a text file (digit.txt) consisting of one column includes three digit numbers whose range are 001-...365. In the same directory, I have data text files. The file name of these data files as follows, jplg3240.18i. Only the jplg part is constant. I need to order jplg data files w.r.t. the numbers in the digit.txt file using the first 5-7 characters of the file names and store them in another text file. For example:



digit.txt=
005
301
350
005
010

data files= jplg001.18i.txt, jplg005.18i.txt, jplg301.18i.txt, jplg350.18i.txt,jplg010.18i.txt, jplg365.18i.txt


Output file should be this one:



output=
jplg005.18i
jplg301.18i
jplg350.18i
jplg005.18i
jplg010.18i









share|improve this question

























  • in short you need to cycle on the content of digit.txt and for the only matched data generate a second file with the list of complete filename, is it that correct?

    – AtomiX84
    Jan 8 at 7:39













  • yes it is true.

    – deepblue_86
    Jan 8 at 7:39
















0















I have a text file (digit.txt) consisting of one column includes three digit numbers whose range are 001-...365. In the same directory, I have data text files. The file name of these data files as follows, jplg3240.18i. Only the jplg part is constant. I need to order jplg data files w.r.t. the numbers in the digit.txt file using the first 5-7 characters of the file names and store them in another text file. For example:



digit.txt=
005
301
350
005
010

data files= jplg001.18i.txt, jplg005.18i.txt, jplg301.18i.txt, jplg350.18i.txt,jplg010.18i.txt, jplg365.18i.txt


Output file should be this one:



output=
jplg005.18i
jplg301.18i
jplg350.18i
jplg005.18i
jplg010.18i









share|improve this question

























  • in short you need to cycle on the content of digit.txt and for the only matched data generate a second file with the list of complete filename, is it that correct?

    – AtomiX84
    Jan 8 at 7:39













  • yes it is true.

    – deepblue_86
    Jan 8 at 7:39














0












0








0








I have a text file (digit.txt) consisting of one column includes three digit numbers whose range are 001-...365. In the same directory, I have data text files. The file name of these data files as follows, jplg3240.18i. Only the jplg part is constant. I need to order jplg data files w.r.t. the numbers in the digit.txt file using the first 5-7 characters of the file names and store them in another text file. For example:



digit.txt=
005
301
350
005
010

data files= jplg001.18i.txt, jplg005.18i.txt, jplg301.18i.txt, jplg350.18i.txt,jplg010.18i.txt, jplg365.18i.txt


Output file should be this one:



output=
jplg005.18i
jplg301.18i
jplg350.18i
jplg005.18i
jplg010.18i









share|improve this question
















I have a text file (digit.txt) consisting of one column includes three digit numbers whose range are 001-...365. In the same directory, I have data text files. The file name of these data files as follows, jplg3240.18i. Only the jplg part is constant. I need to order jplg data files w.r.t. the numbers in the digit.txt file using the first 5-7 characters of the file names and store them in another text file. For example:



digit.txt=
005
301
350
005
010

data files= jplg001.18i.txt, jplg005.18i.txt, jplg301.18i.txt, jplg350.18i.txt,jplg010.18i.txt, jplg365.18i.txt


Output file should be this one:



output=
jplg005.18i
jplg301.18i
jplg350.18i
jplg005.18i
jplg010.18i






scripts text-processing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 8 at 7:59







deepblue_86

















asked Jan 8 at 6:47









deepblue_86deepblue_86

5851023




5851023













  • in short you need to cycle on the content of digit.txt and for the only matched data generate a second file with the list of complete filename, is it that correct?

    – AtomiX84
    Jan 8 at 7:39













  • yes it is true.

    – deepblue_86
    Jan 8 at 7:39



















  • in short you need to cycle on the content of digit.txt and for the only matched data generate a second file with the list of complete filename, is it that correct?

    – AtomiX84
    Jan 8 at 7:39













  • yes it is true.

    – deepblue_86
    Jan 8 at 7:39

















in short you need to cycle on the content of digit.txt and for the only matched data generate a second file with the list of complete filename, is it that correct?

– AtomiX84
Jan 8 at 7:39







in short you need to cycle on the content of digit.txt and for the only matched data generate a second file with the list of complete filename, is it that correct?

– AtomiX84
Jan 8 at 7:39















yes it is true.

– deepblue_86
Jan 8 at 7:39





yes it is true.

– deepblue_86
Jan 8 at 7:39










2 Answers
2






active

oldest

votes


















2














here the while cycle could be good for reach your goal:



while read element
do
if [ -f jplg${element}* ]; then
echo jplg${element}* >> datafiles.txt
fi
done < digit.txt


Code is supposed to be run in to the path were the files are and give you as per result a file list in the file datafiles.txt with the complete name of the file if was matched in the list in the file digit.txt






share|improve this answer


























  • I think my question was understood slightly wrong. I have lots of data files in the directory and the name of these files starts with jplg. The contents of these data files are not related the jplg string.

    – deepblue_86
    Jan 8 at 7:55













  • Update the answer, now only jplg* data will added in the datafiles.txt, anyway was not clear in you original question to me. Sorry for my misunderstanding.

    – AtomiX84
    Jan 8 at 8:21



















0














If you question is concatenate the data from the files listed in digit.txt then an answer is:



ls jplg* | grep -f digit.txt | xargs cat >out.dat


In slo-mo:





  • ls jplg*: lists a superset of all the files you want (you can make that more restrictive if needed)


  • grep -f digit.txt keeps only the lines that contain one number in digit.txt (this assumes that the three digits don't appear anywhere else in file names)


  • xargs cat: applies cat to all the files listed in the grep output






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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1107892%2fcreating-text-file-with-regards-to-file-names%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    here the while cycle could be good for reach your goal:



    while read element
    do
    if [ -f jplg${element}* ]; then
    echo jplg${element}* >> datafiles.txt
    fi
    done < digit.txt


    Code is supposed to be run in to the path were the files are and give you as per result a file list in the file datafiles.txt with the complete name of the file if was matched in the list in the file digit.txt






    share|improve this answer


























    • I think my question was understood slightly wrong. I have lots of data files in the directory and the name of these files starts with jplg. The contents of these data files are not related the jplg string.

      – deepblue_86
      Jan 8 at 7:55













    • Update the answer, now only jplg* data will added in the datafiles.txt, anyway was not clear in you original question to me. Sorry for my misunderstanding.

      – AtomiX84
      Jan 8 at 8:21
















    2














    here the while cycle could be good for reach your goal:



    while read element
    do
    if [ -f jplg${element}* ]; then
    echo jplg${element}* >> datafiles.txt
    fi
    done < digit.txt


    Code is supposed to be run in to the path were the files are and give you as per result a file list in the file datafiles.txt with the complete name of the file if was matched in the list in the file digit.txt






    share|improve this answer


























    • I think my question was understood slightly wrong. I have lots of data files in the directory and the name of these files starts with jplg. The contents of these data files are not related the jplg string.

      – deepblue_86
      Jan 8 at 7:55













    • Update the answer, now only jplg* data will added in the datafiles.txt, anyway was not clear in you original question to me. Sorry for my misunderstanding.

      – AtomiX84
      Jan 8 at 8:21














    2












    2








    2







    here the while cycle could be good for reach your goal:



    while read element
    do
    if [ -f jplg${element}* ]; then
    echo jplg${element}* >> datafiles.txt
    fi
    done < digit.txt


    Code is supposed to be run in to the path were the files are and give you as per result a file list in the file datafiles.txt with the complete name of the file if was matched in the list in the file digit.txt






    share|improve this answer















    here the while cycle could be good for reach your goal:



    while read element
    do
    if [ -f jplg${element}* ]; then
    echo jplg${element}* >> datafiles.txt
    fi
    done < digit.txt


    Code is supposed to be run in to the path were the files are and give you as per result a file list in the file datafiles.txt with the complete name of the file if was matched in the list in the file digit.txt







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 8 at 8:18

























    answered Jan 8 at 7:48









    AtomiX84AtomiX84

    68019




    68019













    • I think my question was understood slightly wrong. I have lots of data files in the directory and the name of these files starts with jplg. The contents of these data files are not related the jplg string.

      – deepblue_86
      Jan 8 at 7:55













    • Update the answer, now only jplg* data will added in the datafiles.txt, anyway was not clear in you original question to me. Sorry for my misunderstanding.

      – AtomiX84
      Jan 8 at 8:21



















    • I think my question was understood slightly wrong. I have lots of data files in the directory and the name of these files starts with jplg. The contents of these data files are not related the jplg string.

      – deepblue_86
      Jan 8 at 7:55













    • Update the answer, now only jplg* data will added in the datafiles.txt, anyway was not clear in you original question to me. Sorry for my misunderstanding.

      – AtomiX84
      Jan 8 at 8:21

















    I think my question was understood slightly wrong. I have lots of data files in the directory and the name of these files starts with jplg. The contents of these data files are not related the jplg string.

    – deepblue_86
    Jan 8 at 7:55







    I think my question was understood slightly wrong. I have lots of data files in the directory and the name of these files starts with jplg. The contents of these data files are not related the jplg string.

    – deepblue_86
    Jan 8 at 7:55















    Update the answer, now only jplg* data will added in the datafiles.txt, anyway was not clear in you original question to me. Sorry for my misunderstanding.

    – AtomiX84
    Jan 8 at 8:21





    Update the answer, now only jplg* data will added in the datafiles.txt, anyway was not clear in you original question to me. Sorry for my misunderstanding.

    – AtomiX84
    Jan 8 at 8:21













    0














    If you question is concatenate the data from the files listed in digit.txt then an answer is:



    ls jplg* | grep -f digit.txt | xargs cat >out.dat


    In slo-mo:





    • ls jplg*: lists a superset of all the files you want (you can make that more restrictive if needed)


    • grep -f digit.txt keeps only the lines that contain one number in digit.txt (this assumes that the three digits don't appear anywhere else in file names)


    • xargs cat: applies cat to all the files listed in the grep output






    share|improve this answer




























      0














      If you question is concatenate the data from the files listed in digit.txt then an answer is:



      ls jplg* | grep -f digit.txt | xargs cat >out.dat


      In slo-mo:





      • ls jplg*: lists a superset of all the files you want (you can make that more restrictive if needed)


      • grep -f digit.txt keeps only the lines that contain one number in digit.txt (this assumes that the three digits don't appear anywhere else in file names)


      • xargs cat: applies cat to all the files listed in the grep output






      share|improve this answer


























        0












        0








        0







        If you question is concatenate the data from the files listed in digit.txt then an answer is:



        ls jplg* | grep -f digit.txt | xargs cat >out.dat


        In slo-mo:





        • ls jplg*: lists a superset of all the files you want (you can make that more restrictive if needed)


        • grep -f digit.txt keeps only the lines that contain one number in digit.txt (this assumes that the three digits don't appear anywhere else in file names)


        • xargs cat: applies cat to all the files listed in the grep output






        share|improve this answer













        If you question is concatenate the data from the files listed in digit.txt then an answer is:



        ls jplg* | grep -f digit.txt | xargs cat >out.dat


        In slo-mo:





        • ls jplg*: lists a superset of all the files you want (you can make that more restrictive if needed)


        • grep -f digit.txt keeps only the lines that contain one number in digit.txt (this assumes that the three digits don't appear anywhere else in file names)


        • xargs cat: applies cat to all the files listed in the grep output







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 8 at 9:46









        xenoidxenoid

        1,4691415




        1,4691415






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • 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%2faskubuntu.com%2fquestions%2f1107892%2fcreating-text-file-with-regards-to-file-names%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

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

             ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕