How to break line after matching case but needs to go back a couple of characters
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
add a comment |
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
add a comment |
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
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
text-processing awk sed text-formatting gawk
edited Dec 9 '18 at 14:25
Jeff Schaller
40.8k1056129
40.8k1056129
asked Dec 8 '18 at 18:30
fdonadonfdonadon
112
112
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
1
TheNg
means "replace globally but start at the Nth occurrence", right?
– terdon♦
Dec 8 '18 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 '18 at 20:39
add a comment |
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
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 '18 at 5:42
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
1
TheNg
means "replace globally but start at the Nth occurrence", right?
– terdon♦
Dec 8 '18 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 '18 at 20:39
add a comment |
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
1
TheNg
means "replace globally but start at the Nth occurrence", right?
– terdon♦
Dec 8 '18 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 '18 at 20:39
add a comment |
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
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
answered Dec 8 '18 at 18:41
steeldriversteeldriver
35.9k35286
35.9k35286
1
TheNg
means "replace globally but start at the Nth occurrence", right?
– terdon♦
Dec 8 '18 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 '18 at 20:39
add a comment |
1
TheNg
means "replace globally but start at the Nth occurrence", right?
– terdon♦
Dec 8 '18 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 '18 at 20:39
1
1
The
Ng
means "replace globally but start at the Nth occurrence", right?– terdon♦
Dec 8 '18 at 18:43
The
Ng
means "replace globally but start at the Nth occurrence", right?– terdon♦
Dec 8 '18 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 '18 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 '18 at 20:39
add a comment |
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
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 '18 at 5:42
add a comment |
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
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 '18 at 5:42
add a comment |
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
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
answered Dec 8 '18 at 18:41
terdon♦terdon
130k32254432
130k32254432
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 '18 at 5:42
add a comment |
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 '18 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 '18 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 '18 at 5:42
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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