How to read the files from one directory and give the file as input of another stored procedure using shell...












1














i am new to writing shell scripts and i have a directory called XML_Files which contains the list of xml files



01.xml

02.xml

03.xml

04.xml


i wanted to read all xml files one by one and send the files to my stored procedure as input argument. so that the stored procedure will process the each xml file one by one accordingly.



I tried to use the for loop to achieve this , but i couldn't get the expected results. it only took the file directory path. Can someone help what i missed in the below script:



XML_FILES='ls -l $Xml_Files/*.xml'
for f in XML_FILES
do
<<Stored procedure>> $f
if [ $? = 0 ]
then
mv $f $XML_Proccesed_Dir/
else
mv $f $XML_error_Dir/
fi
done


i am looking for something which can pick the file from the /xml_files directory and send the files to the stored procedure as an input argument to process the xml files.










share|improve this question






















  • Do you have any sub-directories under XML_Files directory?
    – User123
    13 hours ago












  • NO i dont have any sub directories
    – karthik
    13 hours ago










  • Then you can write a short script in which you first go to the desired directory ,like:cd /desired/directory/ and apply the for loop,like:for i in *.xml; do <<Stored procedure>> $i; done
    – User123
    13 hours ago










  • thanks..i used ${Xml_Files}/*.xml to pick my files and its working
    – karthik
    13 hours ago






  • 1




    "... but i couldn't get the expected results" is not a good problem statement. What is the problem or error? Also see How to create a Minimal, Complete, and Verifiable example.
    – jww
    9 hours ago


















1














i am new to writing shell scripts and i have a directory called XML_Files which contains the list of xml files



01.xml

02.xml

03.xml

04.xml


i wanted to read all xml files one by one and send the files to my stored procedure as input argument. so that the stored procedure will process the each xml file one by one accordingly.



I tried to use the for loop to achieve this , but i couldn't get the expected results. it only took the file directory path. Can someone help what i missed in the below script:



XML_FILES='ls -l $Xml_Files/*.xml'
for f in XML_FILES
do
<<Stored procedure>> $f
if [ $? = 0 ]
then
mv $f $XML_Proccesed_Dir/
else
mv $f $XML_error_Dir/
fi
done


i am looking for something which can pick the file from the /xml_files directory and send the files to the stored procedure as an input argument to process the xml files.










share|improve this question






















  • Do you have any sub-directories under XML_Files directory?
    – User123
    13 hours ago












  • NO i dont have any sub directories
    – karthik
    13 hours ago










  • Then you can write a short script in which you first go to the desired directory ,like:cd /desired/directory/ and apply the for loop,like:for i in *.xml; do <<Stored procedure>> $i; done
    – User123
    13 hours ago










  • thanks..i used ${Xml_Files}/*.xml to pick my files and its working
    – karthik
    13 hours ago






  • 1




    "... but i couldn't get the expected results" is not a good problem statement. What is the problem or error? Also see How to create a Minimal, Complete, and Verifiable example.
    – jww
    9 hours ago
















1












1








1







i am new to writing shell scripts and i have a directory called XML_Files which contains the list of xml files



01.xml

02.xml

03.xml

04.xml


i wanted to read all xml files one by one and send the files to my stored procedure as input argument. so that the stored procedure will process the each xml file one by one accordingly.



I tried to use the for loop to achieve this , but i couldn't get the expected results. it only took the file directory path. Can someone help what i missed in the below script:



XML_FILES='ls -l $Xml_Files/*.xml'
for f in XML_FILES
do
<<Stored procedure>> $f
if [ $? = 0 ]
then
mv $f $XML_Proccesed_Dir/
else
mv $f $XML_error_Dir/
fi
done


i am looking for something which can pick the file from the /xml_files directory and send the files to the stored procedure as an input argument to process the xml files.










share|improve this question













i am new to writing shell scripts and i have a directory called XML_Files which contains the list of xml files



01.xml

02.xml

03.xml

04.xml


i wanted to read all xml files one by one and send the files to my stored procedure as input argument. so that the stored procedure will process the each xml file one by one accordingly.



I tried to use the for loop to achieve this , but i couldn't get the expected results. it only took the file directory path. Can someone help what i missed in the below script:



XML_FILES='ls -l $Xml_Files/*.xml'
for f in XML_FILES
do
<<Stored procedure>> $f
if [ $? = 0 ]
then
mv $f $XML_Proccesed_Dir/
else
mv $f $XML_error_Dir/
fi
done


i am looking for something which can pick the file from the /xml_files directory and send the files to the stored procedure as an input argument to process the xml files.







linux bash shell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 14 hours ago









karthik

133




133












  • Do you have any sub-directories under XML_Files directory?
    – User123
    13 hours ago












  • NO i dont have any sub directories
    – karthik
    13 hours ago










  • Then you can write a short script in which you first go to the desired directory ,like:cd /desired/directory/ and apply the for loop,like:for i in *.xml; do <<Stored procedure>> $i; done
    – User123
    13 hours ago










  • thanks..i used ${Xml_Files}/*.xml to pick my files and its working
    – karthik
    13 hours ago






  • 1




    "... but i couldn't get the expected results" is not a good problem statement. What is the problem or error? Also see How to create a Minimal, Complete, and Verifiable example.
    – jww
    9 hours ago




















  • Do you have any sub-directories under XML_Files directory?
    – User123
    13 hours ago












  • NO i dont have any sub directories
    – karthik
    13 hours ago










  • Then you can write a short script in which you first go to the desired directory ,like:cd /desired/directory/ and apply the for loop,like:for i in *.xml; do <<Stored procedure>> $i; done
    – User123
    13 hours ago










  • thanks..i used ${Xml_Files}/*.xml to pick my files and its working
    – karthik
    13 hours ago






  • 1




    "... but i couldn't get the expected results" is not a good problem statement. What is the problem or error? Also see How to create a Minimal, Complete, and Verifiable example.
    – jww
    9 hours ago


















Do you have any sub-directories under XML_Files directory?
– User123
13 hours ago






Do you have any sub-directories under XML_Files directory?
– User123
13 hours ago














NO i dont have any sub directories
– karthik
13 hours ago




NO i dont have any sub directories
– karthik
13 hours ago












Then you can write a short script in which you first go to the desired directory ,like:cd /desired/directory/ and apply the for loop,like:for i in *.xml; do <<Stored procedure>> $i; done
– User123
13 hours ago




Then you can write a short script in which you first go to the desired directory ,like:cd /desired/directory/ and apply the for loop,like:for i in *.xml; do <<Stored procedure>> $i; done
– User123
13 hours ago












thanks..i used ${Xml_Files}/*.xml to pick my files and its working
– karthik
13 hours ago




thanks..i used ${Xml_Files}/*.xml to pick my files and its working
– karthik
13 hours ago




1




1




"... but i couldn't get the expected results" is not a good problem statement. What is the problem or error? Also see How to create a Minimal, Complete, and Verifiable example.
– jww
9 hours ago






"... but i couldn't get the expected results" is not a good problem statement. What is the problem or error? Also see How to create a Minimal, Complete, and Verifiable example.
– jww
9 hours ago














2 Answers
2






active

oldest

votes


















2














You can just use the wildcard expansion in bash to get the list of xml files inside folder.



for f in ${Xml_Files}/*.xml; do 
something ${f}
....
done


${f} in this loop will be in form:



${Xml_Files}/01.xml
${Xml_Files}/02.xml
${Xml_Files}/03.xml
${Xml_Files}/04.xml


If you need ${f} to be in some other format you should clarify the question more.






share|improve this answer





























    1














    You can also use find to execute a given command on every files found. Example:



    find ${Xml_Files} -name '*.xml' -type f -exec something {} ;


    This will search every file (-type f) with extension xml (-name '*.xml') in the directory ${Xml_Files} and execute something x on every x found.



    You can also use find to execute short bash script, e.g.:



    find ${Xml_Files} -name '*.xml' -type f -exec bash -c 'echo {}' ;





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      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%2fstackoverflow.com%2fquestions%2f53942584%2fhow-to-read-the-files-from-one-directory-and-give-the-file-as-input-of-another-s%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














      You can just use the wildcard expansion in bash to get the list of xml files inside folder.



      for f in ${Xml_Files}/*.xml; do 
      something ${f}
      ....
      done


      ${f} in this loop will be in form:



      ${Xml_Files}/01.xml
      ${Xml_Files}/02.xml
      ${Xml_Files}/03.xml
      ${Xml_Files}/04.xml


      If you need ${f} to be in some other format you should clarify the question more.






      share|improve this answer


























        2














        You can just use the wildcard expansion in bash to get the list of xml files inside folder.



        for f in ${Xml_Files}/*.xml; do 
        something ${f}
        ....
        done


        ${f} in this loop will be in form:



        ${Xml_Files}/01.xml
        ${Xml_Files}/02.xml
        ${Xml_Files}/03.xml
        ${Xml_Files}/04.xml


        If you need ${f} to be in some other format you should clarify the question more.






        share|improve this answer
























          2












          2








          2






          You can just use the wildcard expansion in bash to get the list of xml files inside folder.



          for f in ${Xml_Files}/*.xml; do 
          something ${f}
          ....
          done


          ${f} in this loop will be in form:



          ${Xml_Files}/01.xml
          ${Xml_Files}/02.xml
          ${Xml_Files}/03.xml
          ${Xml_Files}/04.xml


          If you need ${f} to be in some other format you should clarify the question more.






          share|improve this answer












          You can just use the wildcard expansion in bash to get the list of xml files inside folder.



          for f in ${Xml_Files}/*.xml; do 
          something ${f}
          ....
          done


          ${f} in this loop will be in form:



          ${Xml_Files}/01.xml
          ${Xml_Files}/02.xml
          ${Xml_Files}/03.xml
          ${Xml_Files}/04.xml


          If you need ${f} to be in some other format you should clarify the question more.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 13 hours ago









          rAlen

          28818




          28818

























              1














              You can also use find to execute a given command on every files found. Example:



              find ${Xml_Files} -name '*.xml' -type f -exec something {} ;


              This will search every file (-type f) with extension xml (-name '*.xml') in the directory ${Xml_Files} and execute something x on every x found.



              You can also use find to execute short bash script, e.g.:



              find ${Xml_Files} -name '*.xml' -type f -exec bash -c 'echo {}' ;





              share|improve this answer


























                1














                You can also use find to execute a given command on every files found. Example:



                find ${Xml_Files} -name '*.xml' -type f -exec something {} ;


                This will search every file (-type f) with extension xml (-name '*.xml') in the directory ${Xml_Files} and execute something x on every x found.



                You can also use find to execute short bash script, e.g.:



                find ${Xml_Files} -name '*.xml' -type f -exec bash -c 'echo {}' ;





                share|improve this answer
























                  1












                  1








                  1






                  You can also use find to execute a given command on every files found. Example:



                  find ${Xml_Files} -name '*.xml' -type f -exec something {} ;


                  This will search every file (-type f) with extension xml (-name '*.xml') in the directory ${Xml_Files} and execute something x on every x found.



                  You can also use find to execute short bash script, e.g.:



                  find ${Xml_Files} -name '*.xml' -type f -exec bash -c 'echo {}' ;





                  share|improve this answer












                  You can also use find to execute a given command on every files found. Example:



                  find ${Xml_Files} -name '*.xml' -type f -exec something {} ;


                  This will search every file (-type f) with extension xml (-name '*.xml') in the directory ${Xml_Files} and execute something x on every x found.



                  You can also use find to execute short bash script, e.g.:



                  find ${Xml_Files} -name '*.xml' -type f -exec bash -c 'echo {}' ;






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 12 hours ago









                  francesco

                  585212




                  585212






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • 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.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • 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%2fstackoverflow.com%2fquestions%2f53942584%2fhow-to-read-the-files-from-one-directory-and-give-the-file-as-input-of-another-s%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

                      Monofisismo

                      Angular Downloading a file using contenturl with Basic Authentication

                      Olmecas