9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] acme/sam language question
@ 2013-10-29 15:31 Rudolf Sykora
  2013-10-29 16:56 ` Friedrich Psiorz
  0 siblings, 1 reply; 11+ messages in thread
From: Rudolf Sykora @ 2013-10-29 15:31 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello,

how can I set a dot from after A to before B, then make a global
substitution, within thus set dot, of CC to DD and print the resulting
text?

I.e., if there isn't any CC between A and B, just print what's between
A and B, if there is, change it to DD and print all between A and B.

I have sth like this

/A/+#0;/B/-#0 s/CC/DD/g
p

which works if there *is* the CC, but not if it is not there; then the
s command just resets the dot to an empty set.

Thank you
Ruda



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-10-29 15:31 [9fans] acme/sam language question Rudolf Sykora
@ 2013-10-29 16:56 ` Friedrich Psiorz
  2013-10-30  7:47   ` Rudolf Sykora
  0 siblings, 1 reply; 11+ messages in thread
From: Friedrich Psiorz @ 2013-10-29 16:56 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

this should do the trick

/A/+#0;/B/-#0
g/CC/ s/CC/DD/g
p

~Fritz

Am 29.10.2013 16:31, schrieb Rudolf Sykora:
> Hello,
>
> how can I set a dot from after A to before B, then make a global
> substitution, within thus set dot, of CC to DD and print the resulting
> text?
>
> I.e., if there isn't any CC between A and B, just print what's between
> A and B, if there is, change it to DD and print all between A and B.
>
> I have sth like this
>
> /A/+#0;/B/-#0 s/CC/DD/g
> p
>
> which works if there *is* the CC, but not if it is not there; then the
> s command just resets the dot to an empty set.
>
> Thank you
> Ruda
>




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-10-29 16:56 ` Friedrich Psiorz
@ 2013-10-30  7:47   ` Rudolf Sykora
  2013-10-31 15:21     ` Rudolf Sykora
  0 siblings, 1 reply; 11+ messages in thread
From: Rudolf Sykora @ 2013-10-30  7:47 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 29 October 2013 17:56, Friedrich Psiorz <f.psiorz@gmx.de> wrote:
> this should do the trick
>
> /A/+#0;/B/-#0
> g/CC/ s/CC/DD/g
> p

Thanks for the suggestion, the g construct didn't come to my mind.
However, it doesn't work for me: again, if CC is there, it works;
if it's not, then the final dot only contains the match for the /A/ instead
of the whole stretch from A to B.

Ruda



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-10-30  7:47   ` Rudolf Sykora
@ 2013-10-31 15:21     ` Rudolf Sykora
  2013-10-31 15:49       ` Friedrich Psiorz
  0 siblings, 1 reply; 11+ messages in thread
From: Rudolf Sykora @ 2013-10-31 15:21 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 30 October 2013 08:47, Rudolf Sykora <rudolf.sykora@gmail.com> wrote:
> On 29 October 2013 17:56, Friedrich Psiorz <f.psiorz@gmx.de> wrote:
>> this should do the trick
>>
>> /A/+#0;/B/-#0
>> g/CC/ s/CC/DD/g
>> p
>
> Thanks for the suggestion, the g construct didn't come to my mind.
> However, it doesn't work for me: again, if CC is there, it works;
> if it's not, then the final dot only contains the match for the /A/ instead
> of the whole stretch from A to B.
>
> Ruda

no other suggestions?
Thanks
Ruda



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-10-31 15:21     ` Rudolf Sykora
@ 2013-10-31 15:49       ` Friedrich Psiorz
  2013-10-31 19:24         ` Rudolf Sykora
  0 siblings, 1 reply; 11+ messages in thread
From: Friedrich Psiorz @ 2013-10-31 15:49 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

It works for me, but I found another inconsistency.

I tried it on p9p and 9vx, both in acme and sam.
9vx acme is different form the others, for some reason. It does print
the string between A and B, but prints it with CC and not with DD like
sam and like p9p acme.

~Fritz

Am 31.10.2013 16:21, schrieb Rudolf Sykora:
> On 30 October 2013 08:47, Rudolf Sykora <rudolf.sykora@gmail.com> wrote:
>> On 29 October 2013 17:56, Friedrich Psiorz <f.psiorz@gmx.de> wrote:
>>> this should do the trick
>>>
>>> /A/+#0;/B/-#0
>>> g/CC/ s/CC/DD/g
>>> p
>>
>> Thanks for the suggestion, the g construct didn't come to my mind.
>> However, it doesn't work for me: again, if CC is there, it works;
>> if it's not, then the final dot only contains the match for the /A/ instead
>> of the whole stretch from A to B.
>>
>> Ruda
>
> no other suggestions?
> Thanks
> Ruda
>




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-10-31 15:49       ` Friedrich Psiorz
@ 2013-10-31 19:24         ` Rudolf Sykora
  2013-11-06 18:47           ` Rudolf Sykora
  0 siblings, 1 reply; 11+ messages in thread
From: Rudolf Sykora @ 2013-10-31 19:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 31 October 2013 16:49, Friedrich Psiorz <f.psiorz@gmx.de> wrote:
> It works for me, but I found another inconsistency.
>
> I tried it on p9p and 9vx, both in acme and sam.

>>>> /A/+#0;/B/-#0
>>>> g/CC/ s/CC/DD/g
>>>> p

Well. If I use these commands one by one inside p9p acme
(and probably sam, too), I truly get what I want (and what
you say). The problem appears when I want to run it from
a script like this:

sam -d <<EOF $1  >[2] /dev/null
/A/+#0;/B/-#0
g/CC/ s/CC/DD/g
p
EOF

then you get, since the g is on a seperate line, an extra
output from the line before g. And if you try to join g with
the match like

sam -d <<EOF $1  >[2] /dev/null
/A/+#0;/B/-#0 g/CC/ s/CC/DD/g
p
EOF

then you get no output if CC is not between A and B
(although when it is there, you get what I want).
In neither case I am fully satisfied. :)

Thanks
Ruda



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-10-31 19:24         ` Rudolf Sykora
@ 2013-11-06 18:47           ` Rudolf Sykora
  2013-11-06 20:26             ` Micah Stetson
  2013-11-06 20:42             ` Mark van Atten
  0 siblings, 2 replies; 11+ messages in thread
From: Rudolf Sykora @ 2013-11-06 18:47 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 31 October 2013 20:24, Rudolf Sykora <rudolf.sykora@gmail.com> wrote:
> On 31 October 2013 16:49, Friedrich Psiorz <f.psiorz@gmx.de> wrote:
>> It works for me, but I found another inconsistency.
>>
>> I tried it on p9p and 9vx, both in acme and sam.
>
>>>>> /A/+#0;/B/-#0
>>>>> g/CC/ s/CC/DD/g
>>>>> p
>
> Well. If I use these commands one by one inside p9p acme
> (and probably sam, too), I truly get what I want (and what
> you say). The problem appears when I want to run it from
> a script like this:
>
> sam -d <<EOF $1  >[2] /dev/null
> /A/+#0;/B/-#0
> g/CC/ s/CC/DD/g
> p
> EOF
>
> then you get, since the g is on a seperate line, an extra
> output from the line before g. And if you try to join g with
> the match like
>
> sam -d <<EOF $1  >[2] /dev/null
> /A/+#0;/B/-#0 g/CC/ s/CC/DD/g
> p
> EOF
>
> then you get no output if CC is not between A and B
> (although when it is there, you get what I want).
> In neither case I am fully satisfied. :)
>
> Thanks
> Ruda

So far I still do not know how to do it properly...
But it seems nobody here proposes anything...

Thanks for any clue
Ruda



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-11-06 18:47           ` Rudolf Sykora
@ 2013-11-06 20:26             ` Micah Stetson
  2013-11-06 20:42             ` Mark van Atten
  1 sibling, 0 replies; 11+ messages in thread
From: Micah Stetson @ 2013-11-06 20:26 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

What if you specify the address twice like this:

/A/+#0;/B/-#0g/CC/ s/CC/DD/g
/A/+#0;/B/-#0p

That doesn't work if A and B occur more than once in the file or if DD matches A or B. But otherwise, it seems to work for me.

Micah

On Nov 6, 2013, at 10:47 AM, Rudolf Sykora wrote:

> On 31 October 2013 20:24, Rudolf Sykora <rudolf.sykora@gmail.com> wrote:
>> On 31 October 2013 16:49, Friedrich Psiorz <f.psiorz@gmx.de> wrote:
>>> It works for me, but I found another inconsistency.
>>> 
>>> I tried it on p9p and 9vx, both in acme and sam.
>> 
>>>>>> /A/+#0;/B/-#0
>>>>>> g/CC/ s/CC/DD/g
>>>>>> p
>> 
>> Well. If I use these commands one by one inside p9p acme
>> (and probably sam, too), I truly get what I want (and what
>> you say). The problem appears when I want to run it from
>> a script like this:
>> 
>> sam -d <<EOF $1  >[2] /dev/null
>> /A/+#0;/B/-#0
>> g/CC/ s/CC/DD/g
>> p
>> EOF
>> 
>> then you get, since the g is on a seperate line, an extra
>> output from the line before g. And if you try to join g with
>> the match like
>> 
>> sam -d <<EOF $1  >[2] /dev/null
>> /A/+#0;/B/-#0 g/CC/ s/CC/DD/g
>> p
>> EOF
>> 
>> then you get no output if CC is not between A and B
>> (although when it is there, you get what I want).
>> In neither case I am fully satisfied. :)
>> 
>> Thanks
>> Ruda
> 
> So far I still do not know how to do it properly...
> But it seems nobody here proposes anything...
> 
> Thanks for any clue
> Ruda
> 




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-11-06 18:47           ` Rudolf Sykora
  2013-11-06 20:26             ` Micah Stetson
@ 2013-11-06 20:42             ` Mark van Atten
  2013-11-21 13:28               ` Rudolf Sykora
  1 sibling, 1 reply; 11+ messages in thread
From: Mark van Atten @ 2013-11-06 20:42 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I write the script like this:

/A/+#0;/B/-#0 {
g/CC/ s/CC/DD/g
}
p

Mark.


On Wed, Nov 6, 2013 at 7:47 PM, Rudolf Sykora <rudolf.sykora@gmail.com> wrote:
> On 31 October 2013 20:24, Rudolf Sykora <rudolf.sykora@gmail.com> wrote:
>> On 31 October 2013 16:49, Friedrich Psiorz <f.psiorz@gmx.de> wrote:
>>> It works for me, but I found another inconsistency.
>>>
>>> I tried it on p9p and 9vx, both in acme and sam.
>>
>>>>>> /A/+#0;/B/-#0
>>>>>> g/CC/ s/CC/DD/g
>>>>>> p
>>
>> Well. If I use these commands one by one inside p9p acme
>> (and probably sam, too), I truly get what I want (and what
>> you say). The problem appears when I want to run it from
>> a script like this:
>>
>> sam -d <<EOF $1  >[2] /dev/null
>> /A/+#0;/B/-#0
>> g/CC/ s/CC/DD/g
>> p
>> EOF
>>
>> then you get, since the g is on a seperate line, an extra
>> output from the line before g. And if you try to join g with
>> the match like
>>
>> sam -d <<EOF $1  >[2] /dev/null
>> /A/+#0;/B/-#0 g/CC/ s/CC/DD/g
>> p
>> EOF
>>
>> then you get no output if CC is not between A and B
>> (although when it is there, you get what I want).
>> In neither case I am fully satisfied. :)
>>
>> Thanks
>> Ruda
>
> So far I still do not know how to do it properly...
> But it seems nobody here proposes anything...
>
> Thanks for any clue
> Ruda
>



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-11-06 20:42             ` Mark van Atten
@ 2013-11-21 13:28               ` Rudolf Sykora
  2013-11-21 14:52                 ` Mark van Atten
  0 siblings, 1 reply; 11+ messages in thread
From: Rudolf Sykora @ 2013-11-21 13:28 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 6 November 2013 21:42, Mark van Atten <vanattenmark@gmail.com> wrote:
> I write the script like this:
>
> /A/+#0;/B/-#0 {
> g/CC/ s/CC/DD/g
> }
> p

I finally get around to trying this out and (so far) it seems to work.
Thank you!
Ruda



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [9fans] acme/sam language question
  2013-11-21 13:28               ` Rudolf Sykora
@ 2013-11-21 14:52                 ` Mark van Atten
  0 siblings, 0 replies; 11+ messages in thread
From: Mark van Atten @ 2013-11-21 14:52 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> I finally get around to trying this out and (so far) it seems to work.
> Thank you!

You're welcome!

Opening the group at the end of the first line has the effect of
replacing the empty command and its implied p; see sam's man page
under `Miscellany'. This also explains why your lines, without the
grouping, had the desired effect when you executed them one by one
yourself, but not when executed from a script.

Mark.



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-11-21 14:52 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-29 15:31 [9fans] acme/sam language question Rudolf Sykora
2013-10-29 16:56 ` Friedrich Psiorz
2013-10-30  7:47   ` Rudolf Sykora
2013-10-31 15:21     ` Rudolf Sykora
2013-10-31 15:49       ` Friedrich Psiorz
2013-10-31 19:24         ` Rudolf Sykora
2013-11-06 18:47           ` Rudolf Sykora
2013-11-06 20:26             ` Micah Stetson
2013-11-06 20:42             ` Mark van Atten
2013-11-21 13:28               ` Rudolf Sykora
2013-11-21 14:52                 ` Mark van Atten

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).