Replace With Text From The Line Above?











up vote
4
down vote

favorite












I have a text file like this:



ge-0/0/45.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
,Building-Automation,75
,CobraNet,156
,First-Floor-Management,19
,First-Floor-Pavilion,11
,First-Floor-Security,13
,First-Floor-Users,10
,Guest-Wired,3
,Video,150
,Voice_First_Floor,18
,Wireless-Corp,410
,Wireless-Guest,420
,Wireless-Mtg,400
,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
,Voice_First_Floor,18


I looking for a command to grab the first field of the line above and insert it into the line below. So for example, my resulting file would look like this:



ge-0/0/45.0,First-Floor-Security,13
ge-0/0/45.0,Voice_First_Floor,18
ge-0/0/46.0,First-Floor-Security,13
ge-0/0/46.0,Voice_First_Floor,18
ge-0/0/47.0,AV-Media,155
ge-0/0/47.0,Building-Automation,75
ge-0/0/47.0,CobraNet,156
ge-0/0/47.0,First-Floor-Management,19
ge-0/0/47.0,First-Floor-Pavilion,11
ge-0/0/47.0,First-Floor-Security,13
ge-0/0/47.0,First-Floor-Users,10
ge-0/0/47.0,Guest-Wired,3
ge-0/0/47.0,Video,150
ge-0/0/47.0,Voice_First_Floor,18
ge-0/0/47.0,Wireless-Corp,410
ge-0/0/47.0,Wireless-Guest,420
ge-0/0/47.0,Wireless-Mtg,400
ge-0/0/47.0,Wireless-Voice,430
ge-1/0/0.0,First-Floor-Users,10
ge-1/0/0.0,Voice_First_Floor,18


I have some understanding about grouping and backreferences but cannot seem to find a way to search, create a backreference, and then use that backreference in a different line. Is this possible? If so, would you please point me in the right direction?



Thanks,



Drew










share|improve this question


























    up vote
    4
    down vote

    favorite












    I have a text file like this:



    ge-0/0/45.0,First-Floor-Security,13
    ,Voice_First_Floor,18
    ge-0/0/46.0,First-Floor-Security,13
    ,Voice_First_Floor,18
    ge-0/0/47.0,AV-Media,155
    ,Building-Automation,75
    ,CobraNet,156
    ,First-Floor-Management,19
    ,First-Floor-Pavilion,11
    ,First-Floor-Security,13
    ,First-Floor-Users,10
    ,Guest-Wired,3
    ,Video,150
    ,Voice_First_Floor,18
    ,Wireless-Corp,410
    ,Wireless-Guest,420
    ,Wireless-Mtg,400
    ,Wireless-Voice,430
    ge-1/0/0.0,First-Floor-Users,10
    ,Voice_First_Floor,18


    I looking for a command to grab the first field of the line above and insert it into the line below. So for example, my resulting file would look like this:



    ge-0/0/45.0,First-Floor-Security,13
    ge-0/0/45.0,Voice_First_Floor,18
    ge-0/0/46.0,First-Floor-Security,13
    ge-0/0/46.0,Voice_First_Floor,18
    ge-0/0/47.0,AV-Media,155
    ge-0/0/47.0,Building-Automation,75
    ge-0/0/47.0,CobraNet,156
    ge-0/0/47.0,First-Floor-Management,19
    ge-0/0/47.0,First-Floor-Pavilion,11
    ge-0/0/47.0,First-Floor-Security,13
    ge-0/0/47.0,First-Floor-Users,10
    ge-0/0/47.0,Guest-Wired,3
    ge-0/0/47.0,Video,150
    ge-0/0/47.0,Voice_First_Floor,18
    ge-0/0/47.0,Wireless-Corp,410
    ge-0/0/47.0,Wireless-Guest,420
    ge-0/0/47.0,Wireless-Mtg,400
    ge-0/0/47.0,Wireless-Voice,430
    ge-1/0/0.0,First-Floor-Users,10
    ge-1/0/0.0,Voice_First_Floor,18


    I have some understanding about grouping and backreferences but cannot seem to find a way to search, create a backreference, and then use that backreference in a different line. Is this possible? If so, would you please point me in the right direction?



    Thanks,



    Drew










    share|improve this question
























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I have a text file like this:



      ge-0/0/45.0,First-Floor-Security,13
      ,Voice_First_Floor,18
      ge-0/0/46.0,First-Floor-Security,13
      ,Voice_First_Floor,18
      ge-0/0/47.0,AV-Media,155
      ,Building-Automation,75
      ,CobraNet,156
      ,First-Floor-Management,19
      ,First-Floor-Pavilion,11
      ,First-Floor-Security,13
      ,First-Floor-Users,10
      ,Guest-Wired,3
      ,Video,150
      ,Voice_First_Floor,18
      ,Wireless-Corp,410
      ,Wireless-Guest,420
      ,Wireless-Mtg,400
      ,Wireless-Voice,430
      ge-1/0/0.0,First-Floor-Users,10
      ,Voice_First_Floor,18


      I looking for a command to grab the first field of the line above and insert it into the line below. So for example, my resulting file would look like this:



      ge-0/0/45.0,First-Floor-Security,13
      ge-0/0/45.0,Voice_First_Floor,18
      ge-0/0/46.0,First-Floor-Security,13
      ge-0/0/46.0,Voice_First_Floor,18
      ge-0/0/47.0,AV-Media,155
      ge-0/0/47.0,Building-Automation,75
      ge-0/0/47.0,CobraNet,156
      ge-0/0/47.0,First-Floor-Management,19
      ge-0/0/47.0,First-Floor-Pavilion,11
      ge-0/0/47.0,First-Floor-Security,13
      ge-0/0/47.0,First-Floor-Users,10
      ge-0/0/47.0,Guest-Wired,3
      ge-0/0/47.0,Video,150
      ge-0/0/47.0,Voice_First_Floor,18
      ge-0/0/47.0,Wireless-Corp,410
      ge-0/0/47.0,Wireless-Guest,420
      ge-0/0/47.0,Wireless-Mtg,400
      ge-0/0/47.0,Wireless-Voice,430
      ge-1/0/0.0,First-Floor-Users,10
      ge-1/0/0.0,Voice_First_Floor,18


      I have some understanding about grouping and backreferences but cannot seem to find a way to search, create a backreference, and then use that backreference in a different line. Is this possible? If so, would you please point me in the right direction?



      Thanks,



      Drew










      share|improve this question













      I have a text file like this:



      ge-0/0/45.0,First-Floor-Security,13
      ,Voice_First_Floor,18
      ge-0/0/46.0,First-Floor-Security,13
      ,Voice_First_Floor,18
      ge-0/0/47.0,AV-Media,155
      ,Building-Automation,75
      ,CobraNet,156
      ,First-Floor-Management,19
      ,First-Floor-Pavilion,11
      ,First-Floor-Security,13
      ,First-Floor-Users,10
      ,Guest-Wired,3
      ,Video,150
      ,Voice_First_Floor,18
      ,Wireless-Corp,410
      ,Wireless-Guest,420
      ,Wireless-Mtg,400
      ,Wireless-Voice,430
      ge-1/0/0.0,First-Floor-Users,10
      ,Voice_First_Floor,18


      I looking for a command to grab the first field of the line above and insert it into the line below. So for example, my resulting file would look like this:



      ge-0/0/45.0,First-Floor-Security,13
      ge-0/0/45.0,Voice_First_Floor,18
      ge-0/0/46.0,First-Floor-Security,13
      ge-0/0/46.0,Voice_First_Floor,18
      ge-0/0/47.0,AV-Media,155
      ge-0/0/47.0,Building-Automation,75
      ge-0/0/47.0,CobraNet,156
      ge-0/0/47.0,First-Floor-Management,19
      ge-0/0/47.0,First-Floor-Pavilion,11
      ge-0/0/47.0,First-Floor-Security,13
      ge-0/0/47.0,First-Floor-Users,10
      ge-0/0/47.0,Guest-Wired,3
      ge-0/0/47.0,Video,150
      ge-0/0/47.0,Voice_First_Floor,18
      ge-0/0/47.0,Wireless-Corp,410
      ge-0/0/47.0,Wireless-Guest,420
      ge-0/0/47.0,Wireless-Mtg,400
      ge-0/0/47.0,Wireless-Voice,430
      ge-1/0/0.0,First-Floor-Users,10
      ge-1/0/0.0,Voice_First_Floor,18


      I have some understanding about grouping and backreferences but cannot seem to find a way to search, create a backreference, and then use that backreference in a different line. Is this possible? If so, would you please point me in the right direction?



      Thanks,



      Drew







      search replace






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 at 20:32









      610Drew

      211




      211






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote













          Here's a command you could use:



          :g/^,/norm 0kyt,jP


          This uses the "global" command. Here's what it basically does:



          :g/<regex>/<command>


          will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^) a comma (,).



          The command:



          norm 0kyt,jP


          norm means "run these characters like I typed them in normal mode". So 0k goes to the beginning of the last line with a comma. yt, is yank until ,. jP goes back to the line we matched on and pastes from the clipboard before the comma.



          Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as



          ,Building-Automation,75
          ,CobraNet,156
          ,First-Floor-Management,19
          ,First-Floor-Pavilion,11
          ,First-Floor-Security,13
          ,First-Floor-Users,10
          ,Guest-Wired,3
          ,Video,150
          ,Voice_First_Floor,18
          ,Wireless-Corp,410
          ,Wireless-Guest,420
          ,Wireless-Mtg,400
          ,Wireless-Voice,430


          This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.






          share|improve this answer

















          • 1




            That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
            – 610Drew
            Nov 16 at 21:02











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "599"
          };
          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: 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%2fvi.stackexchange.com%2fquestions%2f17986%2freplace-with-text-from-the-line-above%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote













          Here's a command you could use:



          :g/^,/norm 0kyt,jP


          This uses the "global" command. Here's what it basically does:



          :g/<regex>/<command>


          will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^) a comma (,).



          The command:



          norm 0kyt,jP


          norm means "run these characters like I typed them in normal mode". So 0k goes to the beginning of the last line with a comma. yt, is yank until ,. jP goes back to the line we matched on and pastes from the clipboard before the comma.



          Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as



          ,Building-Automation,75
          ,CobraNet,156
          ,First-Floor-Management,19
          ,First-Floor-Pavilion,11
          ,First-Floor-Security,13
          ,First-Floor-Users,10
          ,Guest-Wired,3
          ,Video,150
          ,Voice_First_Floor,18
          ,Wireless-Corp,410
          ,Wireless-Guest,420
          ,Wireless-Mtg,400
          ,Wireless-Voice,430


          This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.






          share|improve this answer

















          • 1




            That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
            – 610Drew
            Nov 16 at 21:02















          up vote
          4
          down vote













          Here's a command you could use:



          :g/^,/norm 0kyt,jP


          This uses the "global" command. Here's what it basically does:



          :g/<regex>/<command>


          will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^) a comma (,).



          The command:



          norm 0kyt,jP


          norm means "run these characters like I typed them in normal mode". So 0k goes to the beginning of the last line with a comma. yt, is yank until ,. jP goes back to the line we matched on and pastes from the clipboard before the comma.



          Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as



          ,Building-Automation,75
          ,CobraNet,156
          ,First-Floor-Management,19
          ,First-Floor-Pavilion,11
          ,First-Floor-Security,13
          ,First-Floor-Users,10
          ,Guest-Wired,3
          ,Video,150
          ,Voice_First_Floor,18
          ,Wireless-Corp,410
          ,Wireless-Guest,420
          ,Wireless-Mtg,400
          ,Wireless-Voice,430


          This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.






          share|improve this answer

















          • 1




            That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
            – 610Drew
            Nov 16 at 21:02













          up vote
          4
          down vote










          up vote
          4
          down vote









          Here's a command you could use:



          :g/^,/norm 0kyt,jP


          This uses the "global" command. Here's what it basically does:



          :g/<regex>/<command>


          will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^) a comma (,).



          The command:



          norm 0kyt,jP


          norm means "run these characters like I typed them in normal mode". So 0k goes to the beginning of the last line with a comma. yt, is yank until ,. jP goes back to the line we matched on and pastes from the clipboard before the comma.



          Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as



          ,Building-Automation,75
          ,CobraNet,156
          ,First-Floor-Management,19
          ,First-Floor-Pavilion,11
          ,First-Floor-Security,13
          ,First-Floor-Users,10
          ,Guest-Wired,3
          ,Video,150
          ,Voice_First_Floor,18
          ,Wireless-Corp,410
          ,Wireless-Guest,420
          ,Wireless-Mtg,400
          ,Wireless-Voice,430


          This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.






          share|improve this answer












          Here's a command you could use:



          :g/^,/norm 0kyt,jP


          This uses the "global" command. Here's what it basically does:



          :g/<regex>/<command>


          will run "command" on every single line that matches the "regex". Our regex is pretty simple: Any line that starts with (^) a comma (,).



          The command:



          norm 0kyt,jP


          norm means "run these characters like I typed them in normal mode". So 0k goes to the beginning of the last line with a comma. yt, is yank until ,. jP goes back to the line we matched on and pastes from the clipboard before the comma.



          Conveniently, this runs each line in order, so it works on multiple entryless lines in a row, such as



          ,Building-Automation,75
          ,CobraNet,156
          ,First-Floor-Management,19
          ,First-Floor-Pavilion,11
          ,First-Floor-Security,13
          ,First-Floor-Users,10
          ,Guest-Wired,3
          ,Video,150
          ,Voice_First_Floor,18
          ,Wireless-Corp,410
          ,Wireless-Guest,420
          ,Wireless-Mtg,400
          ,Wireless-Voice,430


          This is because on the "building automation" line, it will grab the "ge-0/0/47.0" from the previous line, and then paste it on this line. Then, on the "cobraNet" line, it will grab the new "ge-0/0/47.0" from the "building automation" line, etc.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 at 20:57









          DJMcMayhem

          10.1k12860




          10.1k12860








          • 1




            That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
            – 610Drew
            Nov 16 at 21:02














          • 1




            That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
            – 610Drew
            Nov 16 at 21:02








          1




          1




          That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
          – 610Drew
          Nov 16 at 21:02




          That's awesome! Thank you. I would up vote your post but I can't seem to get the confirmation email and confirm to complete my sign up. :/
          – 610Drew
          Nov 16 at 21:02


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17986%2freplace-with-text-from-the-line-above%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

          Сан-Квентин

          8-я гвардейская общевойсковая армия

          Алькесар