Create text files from each link in a list?












0














I have a file with links like this:



http://domain.com/file_name1.mkv
http://domain.com/file_name2.mkv
http://domain.com/file_name3.mkv


... and so on.



I want to create a file for each link with extension .strm and each file to have the name of the file name and to contain the link for that file. So, for the first link the first file name will be file_name1.strm and contain the first link, for the second link the file name will be file_name2.strm and will contain the second link, and so on. How can i do that?



I have a command that is doing something close but it creates only files with the names from words in a file:



sed -e 's/$/.strm/' file | xargs -d 'n' touch









share|improve this question



























    0














    I have a file with links like this:



    http://domain.com/file_name1.mkv
    http://domain.com/file_name2.mkv
    http://domain.com/file_name3.mkv


    ... and so on.



    I want to create a file for each link with extension .strm and each file to have the name of the file name and to contain the link for that file. So, for the first link the first file name will be file_name1.strm and contain the first link, for the second link the file name will be file_name2.strm and will contain the second link, and so on. How can i do that?



    I have a command that is doing something close but it creates only files with the names from words in a file:



    sed -e 's/$/.strm/' file | xargs -d 'n' touch









    share|improve this question

























      0












      0








      0







      I have a file with links like this:



      http://domain.com/file_name1.mkv
      http://domain.com/file_name2.mkv
      http://domain.com/file_name3.mkv


      ... and so on.



      I want to create a file for each link with extension .strm and each file to have the name of the file name and to contain the link for that file. So, for the first link the first file name will be file_name1.strm and contain the first link, for the second link the file name will be file_name2.strm and will contain the second link, and so on. How can i do that?



      I have a command that is doing something close but it creates only files with the names from words in a file:



      sed -e 's/$/.strm/' file | xargs -d 'n' touch









      share|improve this question













      I have a file with links like this:



      http://domain.com/file_name1.mkv
      http://domain.com/file_name2.mkv
      http://domain.com/file_name3.mkv


      ... and so on.



      I want to create a file for each link with extension .strm and each file to have the name of the file name and to contain the link for that file. So, for the first link the first file name will be file_name1.strm and contain the first link, for the second link the file name will be file_name2.strm and will contain the second link, and so on. How can i do that?



      I have a command that is doing something close but it creates only files with the names from words in a file:



      sed -e 's/$/.strm/' file | xargs -d 'n' touch






      files






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      user1800997

      163




      163






















          3 Answers
          3






          active

          oldest

          votes


















          0














          You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/ tells awk to split the lines into fields using / as a delimiter; $0 is the entire line, and $NF is the value of the last field. The print statement executes for every line of the file.



          awk -F/ '{print $0 > $NF}' < input





          share|improve this answer





























            0














            To elaborate your xargs attempt



            xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file


            The first substitution f="${0##*/}" removes the path components of the URL, while the second "${f%.*}.strm" removes and replaces the extension.



            Ex.



            $ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
            $ head *.strm
            ==> file_name1.strm <==
            http://domain.com/file_name1.mkv

            ==> file_name2.strm <==
            http://domain.com/file_name2.mkv

            ==> file_name3.strm <==
            http://domain.com/file_name3.mkv





            share|improve this answer





























              -1














              while read link; do
              echo $link >$link.strm
              done





              share|improve this answer





















              • Issues: The links contain /, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
                – Kusalananda
                37 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
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f491346%2fcreate-text-files-from-each-link-in-a-list%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/ tells awk to split the lines into fields using / as a delimiter; $0 is the entire line, and $NF is the value of the last field. The print statement executes for every line of the file.



              awk -F/ '{print $0 > $NF}' < input





              share|improve this answer


























                0














                You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/ tells awk to split the lines into fields using / as a delimiter; $0 is the entire line, and $NF is the value of the last field. The print statement executes for every line of the file.



                awk -F/ '{print $0 > $NF}' < input





                share|improve this answer
























                  0












                  0








                  0






                  You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/ tells awk to split the lines into fields using / as a delimiter; $0 is the entire line, and $NF is the value of the last field. The print statement executes for every line of the file.



                  awk -F/ '{print $0 > $NF}' < input





                  share|improve this answer












                  You could parse the file with awk and ask it to print the various lines to filenames based on the last element of the URL. The -F/ tells awk to split the lines into fields using / as a delimiter; $0 is the entire line, and $NF is the value of the last field. The print statement executes for every line of the file.



                  awk -F/ '{print $0 > $NF}' < input






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 30 mins ago









                  Jeff Schaller

                  38.7k1053125




                  38.7k1053125

























                      0














                      To elaborate your xargs attempt



                      xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file


                      The first substitution f="${0##*/}" removes the path components of the URL, while the second "${f%.*}.strm" removes and replaces the extension.



                      Ex.



                      $ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
                      $ head *.strm
                      ==> file_name1.strm <==
                      http://domain.com/file_name1.mkv

                      ==> file_name2.strm <==
                      http://domain.com/file_name2.mkv

                      ==> file_name3.strm <==
                      http://domain.com/file_name3.mkv





                      share|improve this answer


























                        0














                        To elaborate your xargs attempt



                        xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file


                        The first substitution f="${0##*/}" removes the path components of the URL, while the second "${f%.*}.strm" removes and replaces the extension.



                        Ex.



                        $ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
                        $ head *.strm
                        ==> file_name1.strm <==
                        http://domain.com/file_name1.mkv

                        ==> file_name2.strm <==
                        http://domain.com/file_name2.mkv

                        ==> file_name3.strm <==
                        http://domain.com/file_name3.mkv





                        share|improve this answer
























                          0












                          0








                          0






                          To elaborate your xargs attempt



                          xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file


                          The first substitution f="${0##*/}" removes the path components of the URL, while the second "${f%.*}.strm" removes and replaces the extension.



                          Ex.



                          $ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
                          $ head *.strm
                          ==> file_name1.strm <==
                          http://domain.com/file_name1.mkv

                          ==> file_name2.strm <==
                          http://domain.com/file_name2.mkv

                          ==> file_name3.strm <==
                          http://domain.com/file_name3.mkv





                          share|improve this answer












                          To elaborate your xargs attempt



                          xargs -L1 sh -c 'f="${0##*/}"; printf "%sn" "$0" > "${f%.*}.strm"' < file


                          The first substitution f="${0##*/}" removes the path components of the URL, while the second "${f%.*}.strm" removes and replaces the extension.



                          Ex.



                          $ xargs -L1 sh -c 'f=${0##*/}; printf "%sn" "$0" > "${f%.*}.strm"' < file
                          $ head *.strm
                          ==> file_name1.strm <==
                          http://domain.com/file_name1.mkv

                          ==> file_name2.strm <==
                          http://domain.com/file_name2.mkv

                          ==> file_name3.strm <==
                          http://domain.com/file_name3.mkv






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered 26 mins ago









                          steeldriver

                          34.2k35083




                          34.2k35083























                              -1














                              while read link; do
                              echo $link >$link.strm
                              done





                              share|improve this answer





















                              • Issues: The links contain /, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
                                – Kusalananda
                                37 mins ago
















                              -1














                              while read link; do
                              echo $link >$link.strm
                              done





                              share|improve this answer





















                              • Issues: The links contain /, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
                                – Kusalananda
                                37 mins ago














                              -1












                              -1








                              -1






                              while read link; do
                              echo $link >$link.strm
                              done





                              share|improve this answer












                              while read link; do
                              echo $link >$link.strm
                              done






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 40 mins ago









                              Erwan

                              1994




                              1994












                              • Issues: The links contain /, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
                                – Kusalananda
                                37 mins ago


















                              • Issues: The links contain /, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
                                – Kusalananda
                                37 mins ago
















                              Issues: The links contain /, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
                              – Kusalananda
                              37 mins ago




                              Issues: The links contain /, so the shell will interpret them as files in weirdly named subdirectories. The variables are unquoted, which may possibly be problematic if any link contains a filename globbing character. No input data is given to the loop. No explanation given in the answer.
                              – Kusalananda
                              37 mins ago


















                              draft saved

                              draft discarded




















































                              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.





                              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%2funix.stackexchange.com%2fquestions%2f491346%2fcreate-text-files-from-each-link-in-a-list%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

                              サソリ

                              広島県道265号伴広島線

                              Accessing regular linux commands in Huawei's Dopra Linux