You are not logged in.

#1 2009-10-01 15:15:10

funkyou
Member
From: Berlin, DE
Registered: 2006-03-19
Posts: 848
Website

[solved] sed: how to put everything after matching string into quotes?

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? smile

Last edited by funkyou (2009-10-02 11:59:30)


want a modular and tweaked KDE for arch? try kdemod

Offline

#2 2009-10-01 15:26:25

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: [solved] sed: how to put everything after matching string into quotes?

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

#3 2009-10-01 15:59:09

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [solved] sed: how to put everything after matching string into quotes?

$ echo "X:''' Y" | sed "s/:''' \(.*\)/:''' \"\1\"/"
X:''' "Y"

\1 refers to everything between \( and \)


This silver ladybug at line 28...

Offline

#4 2009-10-01 18:31:57

funkyou
Member
From: Berlin, DE
Registered: 2006-03-19
Posts: 848
Website

Re: [solved] sed: how to put everything after matching string into quotes?

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! smile


want a modular and tweaked KDE for arch? try kdemod

Offline

#5 2009-10-01 18:51:12

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [solved] sed: how to put everything after matching string into quotes?

What cases does it not work in?

Offline

#6 2009-10-02 11:58:48

funkyou
Member
From: Berlin, DE
Registered: 2006-03-19
Posts: 848
Website

Re: [solved] sed: how to put everything after matching string into quotes?

I was wrong with that, my files were just broken = It works perfectly.


want a modular and tweaked KDE for arch? try kdemod

Offline

#7 2009-10-02 14:10:16

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: [solved] sed: how to put everything after matching string into quotes?

lolilolicon wrote:
$ 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

Board footer

Powered by FluxBB