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











up vote
2
down vote

favorite












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









New contributor




fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    2
    down vote

    favorite












    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









    New contributor




    fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      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









      New contributor




      fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      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









      New contributor




      fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited yesterday









      Jeff Schaller

      37.5k1052121




      37.5k1052121






      New contributor




      fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 days ago









      fdonadon

      112




      112




      New contributor




      fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      fdonadon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote













          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
            2 days ago












          • @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
            2 days ago


















          up vote
          4
          down vote













          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
            yesterday











          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',
          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
          });


          }
          });






          fdonadon is a new contributor. Be nice, and check out our Code of Conduct.










          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








          up vote
          4
          down vote













          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
            2 days ago












          • @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
            2 days ago















          up vote
          4
          down vote













          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
            2 days ago












          • @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
            2 days ago













          up vote
          4
          down vote










          up vote
          4
          down vote









          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 2 days ago









          steeldriver

          33.9k34983




          33.9k34983








          • 1




            The Ng means "replace globally but start at the Nth occurrence", right?
            – terdon
            2 days ago












          • @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
            2 days ago














          • 1




            The Ng means "replace globally but start at the Nth occurrence", right?
            – terdon
            2 days ago












          • @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
            2 days ago








          1




          1




          The Ng means "replace globally but start at the Nth occurrence", right?
          – terdon
          2 days ago






          The Ng means "replace globally but start at the Nth occurrence", right?
          – terdon
          2 days ago














          @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
          2 days ago




          @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
          2 days ago












          up vote
          4
          down vote













          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
            yesterday















          up vote
          4
          down vote













          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
            yesterday













          up vote
          4
          down vote










          up vote
          4
          down vote









          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 2 days ago









          terdon

          127k31245422




          127k31245422












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


















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
















          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
          yesterday




          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
          yesterday










          fdonadon is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          fdonadon is a new contributor. Be nice, and check out our Code of Conduct.













          fdonadon is a new contributor. Be nice, and check out our Code of Conduct.












          fdonadon is a new contributor. Be nice, and check out our Code of Conduct.
















          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