| View previous topic :: View next topic |
| Author |
Message |
cz0 Apprentice

Joined: 13 Jun 2005 Posts: 171 Location: /earth/russia/moscow
|
Posted: Wed Jul 01, 2009 8:19 am Post subject: [SOLVED] sed regexp tamplate, covering 3 strings |
|
|
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 |
|
 |
massimo Veteran

Joined: 22 Jun 2003 Posts: 1046 Location: Austria
|
Posted: Wed Jul 01, 2009 9:09 am Post subject: Re: sed regexp tamplate, covering 3 strings |
|
|
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 |
|
 |
cz0 Apprentice

Joined: 13 Jun 2005 Posts: 171 Location: /earth/russia/moscow
|
Posted: Wed Jul 01, 2009 9:18 am Post subject: |
|
|
| 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 |
|
 |
klixon n00b


Joined: 14 Feb 2006 Posts: 39 Location: Holland
|
Posted: Wed Jul 01, 2009 9:26 am Post subject: |
|
|
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 |
|
 |
massimo Veteran

Joined: 22 Jun 2003 Posts: 1046 Location: Austria
|
Posted: Wed Jul 01, 2009 9:49 am Post subject: |
|
|
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 |
|
 |
cz0 Apprentice

Joined: 13 Jun 2005 Posts: 171 Location: /earth/russia/moscow
|
Posted: Wed Jul 01, 2009 11:10 am Post subject: |
|
|
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 |
|
 |
cz0 Apprentice

Joined: 13 Jun 2005 Posts: 171 Location: /earth/russia/moscow
|
Posted: Wed Jul 01, 2009 11:23 am Post subject: |
|
|
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 |
|
 |
truc Advocate


Joined: 25 Jul 2005 Posts: 3078
|
Posted: Wed Jul 01, 2009 12:57 pm Post subject: |
|
|
instead of You can use
or even,
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 |
|
 |
cz0 Apprentice

Joined: 13 Jun 2005 Posts: 171 Location: /earth/russia/moscow
|
Posted: Wed Jul 01, 2009 1:35 pm Post subject: |
|
|
O-o-o!
| Code: |
sed '/^;database drwpgsql ; only UNIX/{s/^;// ; n ; s/^;// ; n ; s/^;// ; n}'
|
that worked out for me, thanks! |
|
| Back to top |
|
 |
|