Edit text file to add space











up vote
3
down vote

favorite












I have a text file which looks like this



../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb
../pool/main/a/accountsservice/accountsservice_0.6.45-1ubuntu1_amd64.deb
../pool/main/a/accountsservice/gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
../pool/main/a/accountsservice/libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
../pool/main/a/acl/acl_2.2.52-3build1_amd64.deb
../pool/main/a/acl/libacl1_2.2.52-3build1_amd64.deb
../pool/main/a/acl/libacl1-dev_2.2.52-3build1_amd64.deb
../pool/main/a/acpid/acpid_2.0.28-1ubuntu1_amd64.deb
../pool/main/a/acpi-support/acpi-support_0.142_amd64.deb
../pool/main/a/adduser/adduser_3.116ubuntu1_all.deb
../pool/main/a/adium-theme-ubuntu/adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
../pool/main/a/advancecomp/advancecomp_2.1-1_amd64.deb
../pool/main/a/adwaita-icon-theme/adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
../pool/main/a/aisleriot/aisleriot_3.22.5-1_amd64.deb
../pool/main/a/alabaster/python3-alabaster_0.7.8-1_all.deb
../pool/main/a/alembic/alembic_0.9.3-2ubuntu1_all.deb
../pool/main/a/alembic/python3-alembic_0.9.3-2ubuntu1_all.deb
../pool/main/a/alembic/python-alembic_0.9.3-2ubuntu1_all.deb
../pool/main/a/alsa-driver/alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
../pool/main/a/alsa-driver/linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


I want to add space between last slash and name of deb package file e.g.



../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


I tried using sed but couldn't get it right.










share|improve this question


























    up vote
    3
    down vote

    favorite












    I have a text file which looks like this



    ../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb
    ../pool/main/a/accountsservice/accountsservice_0.6.45-1ubuntu1_amd64.deb
    ../pool/main/a/accountsservice/gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
    ../pool/main/a/accountsservice/libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
    ../pool/main/a/acl/acl_2.2.52-3build1_amd64.deb
    ../pool/main/a/acl/libacl1_2.2.52-3build1_amd64.deb
    ../pool/main/a/acl/libacl1-dev_2.2.52-3build1_amd64.deb
    ../pool/main/a/acpid/acpid_2.0.28-1ubuntu1_amd64.deb
    ../pool/main/a/acpi-support/acpi-support_0.142_amd64.deb
    ../pool/main/a/adduser/adduser_3.116ubuntu1_all.deb
    ../pool/main/a/adium-theme-ubuntu/adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
    ../pool/main/a/advancecomp/advancecomp_2.1-1_amd64.deb
    ../pool/main/a/adwaita-icon-theme/adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
    ../pool/main/a/aisleriot/aisleriot_3.22.5-1_amd64.deb
    ../pool/main/a/alabaster/python3-alabaster_0.7.8-1_all.deb
    ../pool/main/a/alembic/alembic_0.9.3-2ubuntu1_all.deb
    ../pool/main/a/alembic/python3-alembic_0.9.3-2ubuntu1_all.deb
    ../pool/main/a/alembic/python-alembic_0.9.3-2ubuntu1_all.deb
    ../pool/main/a/alsa-driver/alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
    ../pool/main/a/alsa-driver/linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


    I want to add space between last slash and name of deb package file e.g.



    ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


    I tried using sed but couldn't get it right.










    share|improve this question
























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have a text file which looks like this



      ../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb
      ../pool/main/a/accountsservice/accountsservice_0.6.45-1ubuntu1_amd64.deb
      ../pool/main/a/accountsservice/gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
      ../pool/main/a/accountsservice/libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
      ../pool/main/a/acl/acl_2.2.52-3build1_amd64.deb
      ../pool/main/a/acl/libacl1_2.2.52-3build1_amd64.deb
      ../pool/main/a/acl/libacl1-dev_2.2.52-3build1_amd64.deb
      ../pool/main/a/acpid/acpid_2.0.28-1ubuntu1_amd64.deb
      ../pool/main/a/acpi-support/acpi-support_0.142_amd64.deb
      ../pool/main/a/adduser/adduser_3.116ubuntu1_all.deb
      ../pool/main/a/adium-theme-ubuntu/adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
      ../pool/main/a/advancecomp/advancecomp_2.1-1_amd64.deb
      ../pool/main/a/adwaita-icon-theme/adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
      ../pool/main/a/aisleriot/aisleriot_3.22.5-1_amd64.deb
      ../pool/main/a/alabaster/python3-alabaster_0.7.8-1_all.deb
      ../pool/main/a/alembic/alembic_0.9.3-2ubuntu1_all.deb
      ../pool/main/a/alembic/python3-alembic_0.9.3-2ubuntu1_all.deb
      ../pool/main/a/alembic/python-alembic_0.9.3-2ubuntu1_all.deb
      ../pool/main/a/alsa-driver/alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
      ../pool/main/a/alsa-driver/linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


      I want to add space between last slash and name of deb package file e.g.



      ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


      I tried using sed but couldn't get it right.










      share|improve this question













      I have a text file which looks like this



      ../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb
      ../pool/main/a/accountsservice/accountsservice_0.6.45-1ubuntu1_amd64.deb
      ../pool/main/a/accountsservice/gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
      ../pool/main/a/accountsservice/libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
      ../pool/main/a/acl/acl_2.2.52-3build1_amd64.deb
      ../pool/main/a/acl/libacl1_2.2.52-3build1_amd64.deb
      ../pool/main/a/acl/libacl1-dev_2.2.52-3build1_amd64.deb
      ../pool/main/a/acpid/acpid_2.0.28-1ubuntu1_amd64.deb
      ../pool/main/a/acpi-support/acpi-support_0.142_amd64.deb
      ../pool/main/a/adduser/adduser_3.116ubuntu1_all.deb
      ../pool/main/a/adium-theme-ubuntu/adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
      ../pool/main/a/advancecomp/advancecomp_2.1-1_amd64.deb
      ../pool/main/a/adwaita-icon-theme/adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
      ../pool/main/a/aisleriot/aisleriot_3.22.5-1_amd64.deb
      ../pool/main/a/alabaster/python3-alabaster_0.7.8-1_all.deb
      ../pool/main/a/alembic/alembic_0.9.3-2ubuntu1_all.deb
      ../pool/main/a/alembic/python3-alembic_0.9.3-2ubuntu1_all.deb
      ../pool/main/a/alembic/python-alembic_0.9.3-2ubuntu1_all.deb
      ../pool/main/a/alsa-driver/alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
      ../pool/main/a/alsa-driver/linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


      I want to add space between last slash and name of deb package file e.g.



      ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


      I tried using sed but couldn't get it right.







      bash 18.04 sed awk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 2 at 22:40









      harshit

      949




      949






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          sed 's_.*/_& _'


          substitutes everything until the last slash (.*/, regexes are greedy) with itself followed by a space (&␣) in every line.



          Example run



          Provided your text file is called file and resides in the current working directory:



          $ <file sed 's_.*/_& _'
          ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
          ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
          ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
          ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
          ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
          ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
          ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
          ../pool/main/a/acpid/ acpid_2.0.28-1ubuntu1_amd64.deb
          ../pool/main/a/acpi-support/ acpi-support_0.142_amd64.deb
          ../pool/main/a/adduser/ adduser_3.116ubuntu1_all.deb
          ../pool/main/a/adium-theme-ubuntu/ adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
          ../pool/main/a/advancecomp/ advancecomp_2.1-1_amd64.deb
          ../pool/main/a/adwaita-icon-theme/ adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
          ../pool/main/a/aisleriot/ aisleriot_3.22.5-1_amd64.deb
          ../pool/main/a/alabaster/ python3-alabaster_0.7.8-1_all.deb
          ../pool/main/a/alembic/ alembic_0.9.3-2ubuntu1_all.deb
          ../pool/main/a/alembic/ python3-alembic_0.9.3-2ubuntu1_all.deb
          ../pool/main/a/alembic/ python-alembic_0.9.3-2ubuntu1_all.deb
          ../pool/main/a/alsa-driver/ alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
          ../pool/main/a/alsa-driver/ linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


          To alter the file in-place, use:



          sed -i 's_.*/_& _' file





          share|improve this answer






























            up vote
            4
            down vote













            What can be done is to use pattern grouping and take advantage of greedy globbing:



            $ echo '../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb' | 
            > sed -r 's/(^.*/)(.*.deb)/1 2/'
            ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


            The parenthesis correspond to integer items in replacement pattern. Thus first parenthesis will greedily match everything to the last slash and the second - everything after that



            With input file in the question:



            $ sed -r 's/(^.*/)(.*.deb)/1 2/' pool.txt
            ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
            ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
            ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
            ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
            ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
            ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
            <...and so on and so forth...>





            share|improve this answer






























              up vote
              1
              down vote













              And for good measure an awk version



              $ awk -F/ '{ OFS="/"; $NF=" "$NF; print; }' /tmp/XXXX
              [...]
              ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
              ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
              [...]




              • -F/ set the field separator to be /

              • for each line of input, taken from /tmp/XXXX which contains your data


                • set output field separator to be / as well


                • NF contains the number of fields, so $NF is the last field

                • Set the last field to be a space string concatenated with the original last field value

                • and print








              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: 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%2f1098007%2fedit-text-file-to-add-space%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








                up vote
                4
                down vote



                accepted










                sed 's_.*/_& _'


                substitutes everything until the last slash (.*/, regexes are greedy) with itself followed by a space (&␣) in every line.



                Example run



                Provided your text file is called file and resides in the current working directory:



                $ <file sed 's_.*/_& _'
                ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
                ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
                ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
                ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
                ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
                ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
                ../pool/main/a/acpid/ acpid_2.0.28-1ubuntu1_amd64.deb
                ../pool/main/a/acpi-support/ acpi-support_0.142_amd64.deb
                ../pool/main/a/adduser/ adduser_3.116ubuntu1_all.deb
                ../pool/main/a/adium-theme-ubuntu/ adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
                ../pool/main/a/advancecomp/ advancecomp_2.1-1_amd64.deb
                ../pool/main/a/adwaita-icon-theme/ adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
                ../pool/main/a/aisleriot/ aisleriot_3.22.5-1_amd64.deb
                ../pool/main/a/alabaster/ python3-alabaster_0.7.8-1_all.deb
                ../pool/main/a/alembic/ alembic_0.9.3-2ubuntu1_all.deb
                ../pool/main/a/alembic/ python3-alembic_0.9.3-2ubuntu1_all.deb
                ../pool/main/a/alembic/ python-alembic_0.9.3-2ubuntu1_all.deb
                ../pool/main/a/alsa-driver/ alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
                ../pool/main/a/alsa-driver/ linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


                To alter the file in-place, use:



                sed -i 's_.*/_& _' file





                share|improve this answer



























                  up vote
                  4
                  down vote



                  accepted










                  sed 's_.*/_& _'


                  substitutes everything until the last slash (.*/, regexes are greedy) with itself followed by a space (&␣) in every line.



                  Example run



                  Provided your text file is called file and resides in the current working directory:



                  $ <file sed 's_.*/_& _'
                  ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
                  ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
                  ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
                  ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
                  ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
                  ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                  ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
                  ../pool/main/a/acpid/ acpid_2.0.28-1ubuntu1_amd64.deb
                  ../pool/main/a/acpi-support/ acpi-support_0.142_amd64.deb
                  ../pool/main/a/adduser/ adduser_3.116ubuntu1_all.deb
                  ../pool/main/a/adium-theme-ubuntu/ adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
                  ../pool/main/a/advancecomp/ advancecomp_2.1-1_amd64.deb
                  ../pool/main/a/adwaita-icon-theme/ adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
                  ../pool/main/a/aisleriot/ aisleriot_3.22.5-1_amd64.deb
                  ../pool/main/a/alabaster/ python3-alabaster_0.7.8-1_all.deb
                  ../pool/main/a/alembic/ alembic_0.9.3-2ubuntu1_all.deb
                  ../pool/main/a/alembic/ python3-alembic_0.9.3-2ubuntu1_all.deb
                  ../pool/main/a/alembic/ python-alembic_0.9.3-2ubuntu1_all.deb
                  ../pool/main/a/alsa-driver/ alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
                  ../pool/main/a/alsa-driver/ linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


                  To alter the file in-place, use:



                  sed -i 's_.*/_& _' file





                  share|improve this answer

























                    up vote
                    4
                    down vote



                    accepted







                    up vote
                    4
                    down vote



                    accepted






                    sed 's_.*/_& _'


                    substitutes everything until the last slash (.*/, regexes are greedy) with itself followed by a space (&␣) in every line.



                    Example run



                    Provided your text file is called file and resides in the current working directory:



                    $ <file sed 's_.*/_& _'
                    ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
                    ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
                    ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
                    ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
                    ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
                    ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                    ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
                    ../pool/main/a/acpid/ acpid_2.0.28-1ubuntu1_amd64.deb
                    ../pool/main/a/acpi-support/ acpi-support_0.142_amd64.deb
                    ../pool/main/a/adduser/ adduser_3.116ubuntu1_all.deb
                    ../pool/main/a/adium-theme-ubuntu/ adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
                    ../pool/main/a/advancecomp/ advancecomp_2.1-1_amd64.deb
                    ../pool/main/a/adwaita-icon-theme/ adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
                    ../pool/main/a/aisleriot/ aisleriot_3.22.5-1_amd64.deb
                    ../pool/main/a/alabaster/ python3-alabaster_0.7.8-1_all.deb
                    ../pool/main/a/alembic/ alembic_0.9.3-2ubuntu1_all.deb
                    ../pool/main/a/alembic/ python3-alembic_0.9.3-2ubuntu1_all.deb
                    ../pool/main/a/alembic/ python-alembic_0.9.3-2ubuntu1_all.deb
                    ../pool/main/a/alsa-driver/ alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
                    ../pool/main/a/alsa-driver/ linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


                    To alter the file in-place, use:



                    sed -i 's_.*/_& _' file





                    share|improve this answer














                    sed 's_.*/_& _'


                    substitutes everything until the last slash (.*/, regexes are greedy) with itself followed by a space (&␣) in every line.



                    Example run



                    Provided your text file is called file and resides in the current working directory:



                    $ <file sed 's_.*/_& _'
                    ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
                    ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
                    ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
                    ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
                    ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
                    ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                    ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
                    ../pool/main/a/acpid/ acpid_2.0.28-1ubuntu1_amd64.deb
                    ../pool/main/a/acpi-support/ acpi-support_0.142_amd64.deb
                    ../pool/main/a/adduser/ adduser_3.116ubuntu1_all.deb
                    ../pool/main/a/adium-theme-ubuntu/ adium-theme-ubuntu_0.3.4-0ubuntu4_all.deb
                    ../pool/main/a/advancecomp/ advancecomp_2.1-1_amd64.deb
                    ../pool/main/a/adwaita-icon-theme/ adwaita-icon-theme_3.28.0-1ubuntu1_all.deb
                    ../pool/main/a/aisleriot/ aisleriot_3.22.5-1_amd64.deb
                    ../pool/main/a/alabaster/ python3-alabaster_0.7.8-1_all.deb
                    ../pool/main/a/alembic/ alembic_0.9.3-2ubuntu1_all.deb
                    ../pool/main/a/alembic/ python3-alembic_0.9.3-2ubuntu1_all.deb
                    ../pool/main/a/alembic/ python-alembic_0.9.3-2ubuntu1_all.deb
                    ../pool/main/a/alsa-driver/ alsa-base_1.0.25+dfsg-0ubuntu5_all.deb
                    ../pool/main/a/alsa-driver/ linux-sound-base_1.0.25+dfsg-0ubuntu5_all.deb


                    To alter the file in-place, use:



                    sed -i 's_.*/_& _' file






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 2 at 23:02

























                    answered Dec 2 at 22:49









                    dessert

                    21.8k55896




                    21.8k55896
























                        up vote
                        4
                        down vote













                        What can be done is to use pattern grouping and take advantage of greedy globbing:



                        $ echo '../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb' | 
                        > sed -r 's/(^.*/)(.*.deb)/1 2/'
                        ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


                        The parenthesis correspond to integer items in replacement pattern. Thus first parenthesis will greedily match everything to the last slash and the second - everything after that



                        With input file in the question:



                        $ sed -r 's/(^.*/)(.*.deb)/1 2/' pool.txt
                        ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
                        ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
                        ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
                        ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
                        ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
                        ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                        <...and so on and so forth...>





                        share|improve this answer



























                          up vote
                          4
                          down vote













                          What can be done is to use pattern grouping and take advantage of greedy globbing:



                          $ echo '../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb' | 
                          > sed -r 's/(^.*/)(.*.deb)/1 2/'
                          ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


                          The parenthesis correspond to integer items in replacement pattern. Thus first parenthesis will greedily match everything to the last slash and the second - everything after that



                          With input file in the question:



                          $ sed -r 's/(^.*/)(.*.deb)/1 2/' pool.txt
                          ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
                          ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
                          ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
                          ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
                          ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
                          ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                          <...and so on and so forth...>





                          share|improve this answer

























                            up vote
                            4
                            down vote










                            up vote
                            4
                            down vote









                            What can be done is to use pattern grouping and take advantage of greedy globbing:



                            $ echo '../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb' | 
                            > sed -r 's/(^.*/)(.*.deb)/1 2/'
                            ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


                            The parenthesis correspond to integer items in replacement pattern. Thus first parenthesis will greedily match everything to the last slash and the second - everything after that



                            With input file in the question:



                            $ sed -r 's/(^.*/)(.*.deb)/1 2/' pool.txt
                            ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
                            ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
                            ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
                            ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
                            ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
                            ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                            <...and so on and so forth...>





                            share|improve this answer














                            What can be done is to use pattern grouping and take advantage of greedy globbing:



                            $ echo '../pool/main/a/aalib/libaa1_1.4p5-44build2_amd64.deb' | 
                            > sed -r 's/(^.*/)(.*.deb)/1 2/'
                            ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb


                            The parenthesis correspond to integer items in replacement pattern. Thus first parenthesis will greedily match everything to the last slash and the second - everything after that



                            With input file in the question:



                            $ sed -r 's/(^.*/)(.*.deb)/1 2/' pool.txt
                            ../pool/main/a/aalib/ libaa1_1.4p5-44build2_amd64.deb
                            ../pool/main/a/accountsservice/ accountsservice_0.6.45-1ubuntu1_amd64.deb
                            ../pool/main/a/accountsservice/ gir1.2-accountsservice-1.0_0.6.45-1ubuntu1_amd64.deb
                            ../pool/main/a/accountsservice/ libaccountsservice0_0.6.45-1ubuntu1_amd64.deb
                            ../pool/main/a/acl/ acl_2.2.52-3build1_amd64.deb
                            ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                            <...and so on and so forth...>






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 2 at 22:59

























                            answered Dec 2 at 22:49









                            Sergiy Kolodyazhnyy

                            69k9143303




                            69k9143303






















                                up vote
                                1
                                down vote













                                And for good measure an awk version



                                $ awk -F/ '{ OFS="/"; $NF=" "$NF; print; }' /tmp/XXXX
                                [...]
                                ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                                ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
                                [...]




                                • -F/ set the field separator to be /

                                • for each line of input, taken from /tmp/XXXX which contains your data


                                  • set output field separator to be / as well


                                  • NF contains the number of fields, so $NF is the last field

                                  • Set the last field to be a space string concatenated with the original last field value

                                  • and print








                                share|improve this answer

























                                  up vote
                                  1
                                  down vote













                                  And for good measure an awk version



                                  $ awk -F/ '{ OFS="/"; $NF=" "$NF; print; }' /tmp/XXXX
                                  [...]
                                  ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                                  ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
                                  [...]




                                  • -F/ set the field separator to be /

                                  • for each line of input, taken from /tmp/XXXX which contains your data


                                    • set output field separator to be / as well


                                    • NF contains the number of fields, so $NF is the last field

                                    • Set the last field to be a space string concatenated with the original last field value

                                    • and print








                                  share|improve this answer























                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    And for good measure an awk version



                                    $ awk -F/ '{ OFS="/"; $NF=" "$NF; print; }' /tmp/XXXX
                                    [...]
                                    ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                                    ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
                                    [...]




                                    • -F/ set the field separator to be /

                                    • for each line of input, taken from /tmp/XXXX which contains your data


                                      • set output field separator to be / as well


                                      • NF contains the number of fields, so $NF is the last field

                                      • Set the last field to be a space string concatenated with the original last field value

                                      • and print








                                    share|improve this answer












                                    And for good measure an awk version



                                    $ awk -F/ '{ OFS="/"; $NF=" "$NF; print; }' /tmp/XXXX
                                    [...]
                                    ../pool/main/a/acl/ libacl1_2.2.52-3build1_amd64.deb
                                    ../pool/main/a/acl/ libacl1-dev_2.2.52-3build1_amd64.deb
                                    [...]




                                    • -F/ set the field separator to be /

                                    • for each line of input, taken from /tmp/XXXX which contains your data


                                      • set output field separator to be / as well


                                      • NF contains the number of fields, so $NF is the last field

                                      • Set the last field to be a space string concatenated with the original last field value

                                      • and print









                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Dec 3 at 1:41









                                    jonathanjo

                                    1313




                                    1313






























                                        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.





                                        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%2faskubuntu.com%2fquestions%2f1098007%2fedit-text-file-to-add-space%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

                                        Quarter-circle Tiles

                                        build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

                                        Mont Emei