Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] sed regexp tamplate, covering 3 strings
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
cz0
Apprentice
Apprentice


Joined: 13 Jun 2005
Posts: 171
Location: /earth/russia/moscow

PostPosted: Wed Jul 01, 2009 8:19 am    Post subject: [SOLVED] sed regexp tamplate, covering 3 strings Reply with quote

Hi folks!
I'm trying to make a tamplate for sed (s command) to replace 3 strings, looking like this:
;aaaaaaa
;bbbbbbb
;cccccccc

with strings like this:
aaaaaaa
bbbbbbb
ddddddd

but as it's 3 strings new line eatch, I have no clue how to make a tamplate. sed is called from bash script. I've tryed something like this:
Code:

cat filename | sed 's/;aaaaaaa{/*/*}/somthing'

and
Code:

cat filename | sed 's/;aaaaaaa{
/*
/*
}/somthing'

and bad luck :(
Can anybody help me as I'm already feeling sick of it.


Last edited by cz0 on Wed Jul 01, 2009 1:58 pm; edited 1 time in total
Back to top
View user's profile Send private message
massimo
Veteran
Veteran


Joined: 22 Jun 2003
Posts: 1046
Location: Austria

PostPosted: Wed Jul 01, 2009 9:09 am    Post subject: Re: sed regexp tamplate, covering 3 strings Reply with quote

I'm not sure what you're really trying to do but how about cat foo | sed -e 's...' -e 's...' -e 's...'?
_________________
Hello, IT. Have you tried turning it off and on again?
Back to top
View user's profile Send private message
cz0
Apprentice
Apprentice


Joined: 13 Jun 2005
Posts: 171
Location: /earth/russia/moscow

PostPosted: Wed Jul 01, 2009 9:18 am    Post subject: Reply with quote

Strings 'aaaaaaa' and 'ccccccc' are unique, but string 'bbbbbbb' is't, a have 6 different blocks whith line bbbbbbb, so. if I use a separate tamplate for eatch 3 lines a will have all bbbbbbb strings modifyed from all 6 blocks. So, that why I have to make a single tamplate for 3 lines.
Back to top
View user's profile Send private message
klixon
n00b
n00b


Joined: 14 Feb 2006
Posts: 39
Location: Holland

PostPosted: Wed Jul 01, 2009 9:26 am    Post subject: Reply with quote

i replied in your duplicate thread in otw (it is closed)... see if that works
_________________
Stand back, intruder, or I'll blast you out of space. I am Klixon and I don't want any dealings with you human lifeforms... I'm a cyborg!
Back to top
View user's profile Send private message
massimo
Veteran
Veteran


Joined: 22 Jun 2003
Posts: 1046
Location: Austria

PostPosted: Wed Jul 01, 2009 9:49 am    Post subject: Reply with quote

How about awk?

cat foo | awk -v RS= 'sub(/;aaaaaaa\n;bbbbbbb\n;ccccccc/,"aaaaaa\nbbbbbb\ndddddd")'
_________________
Hello, IT. Have you tried turning it off and on again?
Back to top
View user's profile Send private message
cz0
Apprentice
Apprentice


Joined: 13 Jun 2005
Posts: 171
Location: /earth/russia/moscow

PostPosted: Wed Jul 01, 2009 11:10 am    Post subject: Reply with quote

No luck :,,(
2 klixon:
the command was
Code:

sed s/;aaaaaaaa.*.*\)/test/

(as dot is known to be interpreted as new line) and it gave me:
Code:

test
;bbbbbbb
;cccccccc


2 massimo: just empty output :(
Back to top
View user's profile Send private message
cz0
Apprentice
Apprentice


Joined: 13 Jun 2005
Posts: 171
Location: /earth/russia/moscow

PostPosted: Wed Jul 01, 2009 11:23 am    Post subject: Reply with quote

Well, string 'aaaaaaa' is unique and means, that next two lines will be bbbbbbb and ccccccc, so regexp maybe:
"a line, starting with aaaaaaa and next two lines after it".
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3078

PostPosted: Wed Jul 01, 2009 12:57 pm    Post subject: Reply with quote

instead of
Quote:
Code:
cat file | sed ...
or
Code:
cat file | awk ...
You can use
Code:
awk ... file
or even,
Code:
<file sed ...




And, the problem is still not very clear to me(mind giving us *real* example?), but from the last comment, this may be what you want:
Code:
<file sed '/^;aaaaaaa/{s/^;// ; n ; s/^;// ; n ; s/^;ccccccc/ddddddd/ }'

_________________
The End of the Internet!
Back to top
View user's profile Send private message
cz0
Apprentice
Apprentice


Joined: 13 Jun 2005
Posts: 171
Location: /earth/russia/moscow

PostPosted: Wed Jul 01, 2009 1:35 pm    Post subject: Reply with quote

O-o-o!
Code:

sed '/^;database drwpgsql ; only UNIX/{s/^;// ; n ; s/^;// ; n ; s/^;// ; n}'

that worked out for me, thanks!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum