How to break line after matching case but needs to go back a couple of characters












2














I have the following sample:





1. TNT 00:00 2. Swing From The Gutters 7:34 3. Ten-Day Interval 13:29 4. I Set My Face To The Hillside 18:16 5. The Equator 24:26 6. A Simple Way To Go Faster Than Light That Does Not Work 28:27 7. The Suspension Bridge At Iguazu Falls 32:03 8. Four-Day Interval 37:42 9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29 10. Almost Always Is Nearly Enough 50:01 11. Jetty 52:45 12. Everglade 1:01:09 1:05:32


Which I want to convert into:



1. TNT 00:00 
2. Swing From The Gutters 7:34
3. Ten-Day Interval 13:29
4. I Set My Face To The Hillside 18:16
5. The Equator 24:26
6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
7. The Suspension Bridge At Iguazu Falls 32:03
8. Four-Day Interval 37:42
9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
10. Almost Always Is Nearly Enough 50:01
11. Jetty 52:45
12. Everglade 1:01:09 1:05:32


The logical path I was following is that I know there will always be a "dot" (.) that comes with the number of the track and I can use it as a guideline for the breaks. The trouble is, it has to crawl back one or two characters in order to keep the number of the tracks.










share|improve this question





























    2














    I have the following sample:





    1. TNT 00:00 2. Swing From The Gutters 7:34 3. Ten-Day Interval 13:29 4. I Set My Face To The Hillside 18:16 5. The Equator 24:26 6. A Simple Way To Go Faster Than Light That Does Not Work 28:27 7. The Suspension Bridge At Iguazu Falls 32:03 8. Four-Day Interval 37:42 9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29 10. Almost Always Is Nearly Enough 50:01 11. Jetty 52:45 12. Everglade 1:01:09 1:05:32


    Which I want to convert into:



    1. TNT 00:00 
    2. Swing From The Gutters 7:34
    3. Ten-Day Interval 13:29
    4. I Set My Face To The Hillside 18:16
    5. The Equator 24:26
    6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
    7. The Suspension Bridge At Iguazu Falls 32:03
    8. Four-Day Interval 37:42
    9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
    10. Almost Always Is Nearly Enough 50:01
    11. Jetty 52:45
    12. Everglade 1:01:09 1:05:32


    The logical path I was following is that I know there will always be a "dot" (.) that comes with the number of the track and I can use it as a guideline for the breaks. The trouble is, it has to crawl back one or two characters in order to keep the number of the tracks.










    share|improve this question



























      2












      2








      2







      I have the following sample:





      1. TNT 00:00 2. Swing From The Gutters 7:34 3. Ten-Day Interval 13:29 4. I Set My Face To The Hillside 18:16 5. The Equator 24:26 6. A Simple Way To Go Faster Than Light That Does Not Work 28:27 7. The Suspension Bridge At Iguazu Falls 32:03 8. Four-Day Interval 37:42 9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29 10. Almost Always Is Nearly Enough 50:01 11. Jetty 52:45 12. Everglade 1:01:09 1:05:32


      Which I want to convert into:



      1. TNT 00:00 
      2. Swing From The Gutters 7:34
      3. Ten-Day Interval 13:29
      4. I Set My Face To The Hillside 18:16
      5. The Equator 24:26
      6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
      7. The Suspension Bridge At Iguazu Falls 32:03
      8. Four-Day Interval 37:42
      9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
      10. Almost Always Is Nearly Enough 50:01
      11. Jetty 52:45
      12. Everglade 1:01:09 1:05:32


      The logical path I was following is that I know there will always be a "dot" (.) that comes with the number of the track and I can use it as a guideline for the breaks. The trouble is, it has to crawl back one or two characters in order to keep the number of the tracks.










      share|improve this question















      I have the following sample:





      1. TNT 00:00 2. Swing From The Gutters 7:34 3. Ten-Day Interval 13:29 4. I Set My Face To The Hillside 18:16 5. The Equator 24:26 6. A Simple Way To Go Faster Than Light That Does Not Work 28:27 7. The Suspension Bridge At Iguazu Falls 32:03 8. Four-Day Interval 37:42 9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29 10. Almost Always Is Nearly Enough 50:01 11. Jetty 52:45 12. Everglade 1:01:09 1:05:32


      Which I want to convert into:



      1. TNT 00:00 
      2. Swing From The Gutters 7:34
      3. Ten-Day Interval 13:29
      4. I Set My Face To The Hillside 18:16
      5. The Equator 24:26
      6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
      7. The Suspension Bridge At Iguazu Falls 32:03
      8. Four-Day Interval 37:42
      9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
      10. Almost Always Is Nearly Enough 50:01
      11. Jetty 52:45
      12. Everglade 1:01:09 1:05:32


      The logical path I was following is that I know there will always be a "dot" (.) that comes with the number of the track and I can use it as a guideline for the breaks. The trouble is, it has to crawl back one or two characters in order to keep the number of the tracks.







      text-processing awk sed text-formatting gawk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 9 at 14:25









      Jeff Schaller

      38.5k1053125




      38.5k1053125










      asked Dec 8 at 18:30









      fdonadon

      112




      112






















          2 Answers
          2






          active

          oldest

          votes


















          4














          At least with GNU sed, you can insert a newline before all but the first matching sequence using a 2g modifier:



          sed -E 's/[0-9]+./n&/2g' file





          share|improve this answer

















          • 1




            The Ng means "replace globally but start at the Nth occurrence", right?
            – terdon
            Dec 8 at 18:43












          • @terdon yes that's right - or as the manual puts it, "ignore matches before the numberth, and then match and replace all matches from the numberth on"
            – steeldriver
            Dec 8 at 20:39



















          4














          Just capture the number and the dot and insert a newline before them:



          $ perl -pe 's/s(d+.)/n$1/g' file 
          1. TNT 00:00
          2. Swing From The Gutters 7:34
          3. Ten-Day Interval 13:29
          4. I Set My Face To The Hillside 18:16
          5. The Equator 24:26
          6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
          7. The Suspension Bridge At Iguazu Falls 32:03
          8. Four-Day Interval 37:42
          9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
          10. Almost Always Is Nearly Enough 50:01
          11. Jetty 52:45
          12. Everglade 1:01:09 1:05:32





          share|improve this answer





















          • I'd just like to point out that both answers on this question came in: (a) 10.5 minutes after it was asked, and more amazingly, (b) 15 seconds apart. (#TooSlow, @terdon! 😉)
            – FeRD
            Dec 9 at 5:42











          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%2f486818%2fhow-to-break-line-after-matching-case-but-needs-to-go-back-a-couple-of-character%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









          4














          At least with GNU sed, you can insert a newline before all but the first matching sequence using a 2g modifier:



          sed -E 's/[0-9]+./n&/2g' file





          share|improve this answer

















          • 1




            The Ng means "replace globally but start at the Nth occurrence", right?
            – terdon
            Dec 8 at 18:43












          • @terdon yes that's right - or as the manual puts it, "ignore matches before the numberth, and then match and replace all matches from the numberth on"
            – steeldriver
            Dec 8 at 20:39
















          4














          At least with GNU sed, you can insert a newline before all but the first matching sequence using a 2g modifier:



          sed -E 's/[0-9]+./n&/2g' file





          share|improve this answer

















          • 1




            The Ng means "replace globally but start at the Nth occurrence", right?
            – terdon
            Dec 8 at 18:43












          • @terdon yes that's right - or as the manual puts it, "ignore matches before the numberth, and then match and replace all matches from the numberth on"
            – steeldriver
            Dec 8 at 20:39














          4












          4








          4






          At least with GNU sed, you can insert a newline before all but the first matching sequence using a 2g modifier:



          sed -E 's/[0-9]+./n&/2g' file





          share|improve this answer












          At least with GNU sed, you can insert a newline before all but the first matching sequence using a 2g modifier:



          sed -E 's/[0-9]+./n&/2g' file






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 8 at 18:41









          steeldriver

          34.2k35083




          34.2k35083








          • 1




            The Ng means "replace globally but start at the Nth occurrence", right?
            – terdon
            Dec 8 at 18:43












          • @terdon yes that's right - or as the manual puts it, "ignore matches before the numberth, and then match and replace all matches from the numberth on"
            – steeldriver
            Dec 8 at 20:39














          • 1




            The Ng means "replace globally but start at the Nth occurrence", right?
            – terdon
            Dec 8 at 18:43












          • @terdon yes that's right - or as the manual puts it, "ignore matches before the numberth, and then match and replace all matches from the numberth on"
            – steeldriver
            Dec 8 at 20:39








          1




          1




          The Ng means "replace globally but start at the Nth occurrence", right?
          – terdon
          Dec 8 at 18:43






          The Ng means "replace globally but start at the Nth occurrence", right?
          – terdon
          Dec 8 at 18:43














          @terdon yes that's right - or as the manual puts it, "ignore matches before the numberth, and then match and replace all matches from the numberth on"
          – steeldriver
          Dec 8 at 20:39




          @terdon yes that's right - or as the manual puts it, "ignore matches before the numberth, and then match and replace all matches from the numberth on"
          – steeldriver
          Dec 8 at 20:39













          4














          Just capture the number and the dot and insert a newline before them:



          $ perl -pe 's/s(d+.)/n$1/g' file 
          1. TNT 00:00
          2. Swing From The Gutters 7:34
          3. Ten-Day Interval 13:29
          4. I Set My Face To The Hillside 18:16
          5. The Equator 24:26
          6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
          7. The Suspension Bridge At Iguazu Falls 32:03
          8. Four-Day Interval 37:42
          9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
          10. Almost Always Is Nearly Enough 50:01
          11. Jetty 52:45
          12. Everglade 1:01:09 1:05:32





          share|improve this answer





















          • I'd just like to point out that both answers on this question came in: (a) 10.5 minutes after it was asked, and more amazingly, (b) 15 seconds apart. (#TooSlow, @terdon! 😉)
            – FeRD
            Dec 9 at 5:42
















          4














          Just capture the number and the dot and insert a newline before them:



          $ perl -pe 's/s(d+.)/n$1/g' file 
          1. TNT 00:00
          2. Swing From The Gutters 7:34
          3. Ten-Day Interval 13:29
          4. I Set My Face To The Hillside 18:16
          5. The Equator 24:26
          6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
          7. The Suspension Bridge At Iguazu Falls 32:03
          8. Four-Day Interval 37:42
          9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
          10. Almost Always Is Nearly Enough 50:01
          11. Jetty 52:45
          12. Everglade 1:01:09 1:05:32





          share|improve this answer





















          • I'd just like to point out that both answers on this question came in: (a) 10.5 minutes after it was asked, and more amazingly, (b) 15 seconds apart. (#TooSlow, @terdon! 😉)
            – FeRD
            Dec 9 at 5:42














          4












          4








          4






          Just capture the number and the dot and insert a newline before them:



          $ perl -pe 's/s(d+.)/n$1/g' file 
          1. TNT 00:00
          2. Swing From The Gutters 7:34
          3. Ten-Day Interval 13:29
          4. I Set My Face To The Hillside 18:16
          5. The Equator 24:26
          6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
          7. The Suspension Bridge At Iguazu Falls 32:03
          8. Four-Day Interval 37:42
          9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
          10. Almost Always Is Nearly Enough 50:01
          11. Jetty 52:45
          12. Everglade 1:01:09 1:05:32





          share|improve this answer












          Just capture the number and the dot and insert a newline before them:



          $ perl -pe 's/s(d+.)/n$1/g' file 
          1. TNT 00:00
          2. Swing From The Gutters 7:34
          3. Ten-Day Interval 13:29
          4. I Set My Face To The Hillside 18:16
          5. The Equator 24:26
          6. A Simple Way To Go Faster Than Light That Does Not Work 28:27
          7. The Suspension Bridge At Iguazu Falls 32:03
          8. Four-Day Interval 37:42
          9. In Sarah, Mencken, Christ And Beethoven There Were Women And Men 42:29
          10. Almost Always Is Nearly Enough 50:01
          11. Jetty 52:45
          12. Everglade 1:01:09 1:05:32






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 8 at 18:41









          terdon

          128k31246423




          128k31246423












          • I'd just like to point out that both answers on this question came in: (a) 10.5 minutes after it was asked, and more amazingly, (b) 15 seconds apart. (#TooSlow, @terdon! 😉)
            – FeRD
            Dec 9 at 5:42


















          • I'd just like to point out that both answers on this question came in: (a) 10.5 minutes after it was asked, and more amazingly, (b) 15 seconds apart. (#TooSlow, @terdon! 😉)
            – FeRD
            Dec 9 at 5:42
















          I'd just like to point out that both answers on this question came in: (a) 10.5 minutes after it was asked, and more amazingly, (b) 15 seconds apart. (#TooSlow, @terdon! 😉)
          – FeRD
          Dec 9 at 5:42




          I'd just like to point out that both answers on this question came in: (a) 10.5 minutes after it was asked, and more amazingly, (b) 15 seconds apart. (#TooSlow, @terdon! 😉)
          – FeRD
          Dec 9 at 5:42


















          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%2f486818%2fhow-to-break-line-after-matching-case-but-needs-to-go-back-a-couple-of-character%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

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy