You are not logged in.
Hi there,
i am currently trying to learn a bit more about sed (just did some substitution and other easy stuff before), and now there is something i do not understand at all: how to put everything after a matching string into quotes.
Here is an example. I have some files with lines looking like that:
*'''0000?xx:''' Something
*'''0000x?x:''' Something Again
*'''0000xx?:''' And Again Something
and i want to put the complete "something" strings following after >:''' < into quotes, so the outcome looks like that:
*'''0000xx?:''' ''And Again Something''
Because every line is different in the files, i think i can only use >:''' < as the "marker" or delimiter for sed, because this is the only thing that never changes. And here starts the fun, i've already spent hours reading and trying stuff, but no solution in sight.
So i am asking the pros here: Any hints or ideas?
Last edited by funkyou (2009-10-02 11:59:30)
want a modular and tweaked KDE for arch? try kdemod
Offline
Take a look at man column, it helps you categorize your input into, well, columns, delimited by a string you define. Also, have you read man 7 regex? There are some examples that might show you the way.
Offline
$ echo "X:''' Y" | sed "s/:''' \(.*\)/:''' \"\1\"/"
X:''' "Y"
\1 refers to everything between \( and \)
This silver ladybug at line 28...
Offline
Thank you both, also for the example. It works fine, just not in all cases, but thats a good start to learn from here.
Thanks again!
want a modular and tweaked KDE for arch? try kdemod
Offline
What cases does it not work in?
Offline
I was wrong with that, my files were just broken = It works perfectly.
want a modular and tweaked KDE for arch? try kdemod
Offline
$ echo "X:''' Y" | sed "s/:''' \(.*\)/:''' \"\1\"/" X:''' "Y"
\1 refers to everything between \( and \)
Thanks from me, too. I can never work out what to do with 's and "s and when to escape them. This provides a nice starting point.
Offline