subtitute pattern that crosses new line
This is snippet of the file I'm trying to change:
Code:
1: 00:02:43:24 00:02:45:22 01:23 Code:
1 Code:
sed -r -e '/^[0-9]+:/{N;s/(^[0-9]+):\n\s+/\1\n}' file.txt On the other hand, I'm not sure using \n on both sides of the substitute sentence is going to work. I did manage to create a new line after the number with each those lines begin, but I wasn't able to delete the space that preceeds the time interval, so that's not effective: Code:
sed -r -e '/^[0-9]+:/{N;s/(^[0-9]+):/\1\n/g}' file.txt [later edit] Now I've realised that the initial idea doesn't make sense, as there is no \n in the initial line, so there can't possibly be a match there. So this seems to be doing what I'm looking for :) Code:
sed -r -e '/^[0-9]+:/{N;s/(^[0-9]+):\s+/\1\n/g}' file.txt |
Good work!
You can simplify that a bit: Code:
sed -r 's/^([0-9]+:)\s*/\1\n/' file.txt |
But I'm trying to get rid of the colon :)
|
Quote:
Easy to fix, simply move the capture parenthesis: Code:
sed -r 's/^([0-9]+):\s*/\1\n/' file.txt |
I thought \n doesn't work without N. But now I realise that what N does is simply to translate the end of line into \n, so that it can be matched, whereas in your example (and mine too actually), \n is part of the string that substitutes, not the string that is being substituted.
And yes, it doesn't make too much sense to match a string and create a { } sentence if the substituted string is going to be the same with the initial string (the one before the open brace) I'm trying to match. I see what you're getting at. Indeed, much simpler :) |
Glad that worked!
Equally glad to see that you are trying to understand it all! Very good exercise and time well spent for us both! |
Thanks for the help :)
|
All times are GMT -5. The time now is 10:22 PM. |