Re: run on regex line?

2024-01-20 Thread William Michels via perl6-users
Just want to elaborate on the two different ways of combining statements 
mentioned earlier.


1A.  If you're using `-pe` command line flags, you use `s///` and combine 
statements with `;` semicolon:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/;  s/red/blue/'
lilacs are blue

1B.  Using `-pe` with `s///` but `andthen` instead of `;` is apparently a 
mistake--you don't get what you expect:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/ andthen s/red/blue/'
lilacs are red


2A.  Conversely, if you're using `-ne` command line flags, you use `S///` and 
combine statements with `andthen`:

~$ echo 'roses are red' | raku -ne 'S/roses/lilacs/ andthen S/red/blue/.put'
lilacs are blue

2B.  Again, using `-ne` with `S///` but `;` instead of `andthen` is apparently 
a mistake--you don't get what you expect:

~$ echo 'roses are red' | raku -ne 'S/roses/lilacs/;  S/red/blue/.put'
roses are blue


HTH, Bill.


> On Jan 20, 2024, at 04:20, Richard Hainsworth  wrote:
> Todd,
> You could use Elizabeth Mattijsen's App-rak. It's a Raku utility that does 
> grep, sed, awk.
> Richard



Re: run on regex line?

2024-01-20 Thread Richard Hainsworth

Todd,

You could use Elizabeth Mattijsen's App-rak. It's a Raku utility that 
does grep, sed, awk.


Richard

On 20/01/2024 10:53, ToddAndMargo via perl6-users wrote:

On 1/20/24 01:42, William Michels via perl6-users wrote:


On Jan 19, 2024, at 23:49, ToddAndMargo via perl6-users 
 wrote:


Hi All,

Can I do a run on line with a regex like I
just did with sed?

$ zbarimg Screenshot.png | sed -e 's/.*?secret=//' -e 's/&.*//'

Usually I just do two lines in Raku.

Many thanks,
-T



Hi Todd,

Not that I am aware. The naive way is just to pipe them:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/' | raku -pe 
's/red/blue/'

lilacs are blue


The Raku way would be combining those two statements into one Raku call:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/; s/red/blue/'
lilacs are blue



I like this one! It is easy to figure out at a glance.



#OR ("big-S" notation below)

~$ echo 'roses are red' | raku -ne 'S/roses/lilacs/ andthen 
S/red/blue/.put'

lilacs are blue


The `andthen` call reloads the `$_` topic variable. For more 
examples, see:


https://stackoverflow.com/questions/65066358/concatenating-s-in-raku 



HTH, Bill


It does.  Thank you!

Raku's regex's spoil me.  sed has to be
the editor from ...

Then again, I still use vi at times.


Re: run on regex line?

2024-01-20 Thread ToddAndMargo via perl6-users

On 1/20/24 01:42, William Michels via perl6-users wrote:


On Jan 19, 2024, at 23:49, ToddAndMargo via perl6-users 
 wrote:


Hi All,

Can I do a run on line with a regex like I
just did with sed?

$ zbarimg Screenshot.png | sed -e 's/.*?secret=//' -e 's/&.*//'

Usually I just do two lines in Raku.

Many thanks,
-T



Hi Todd,

Not that I am aware. The naive way is just to pipe them:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/' | raku -pe 
's/red/blue/'

lilacs are blue


The Raku way would be combining those two statements into one Raku call:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/; s/red/blue/'
lilacs are blue



I like this one! It is easy to figure out at a glance.



#OR ("big-S" notation below)

~$ echo 'roses are red' | raku -ne 'S/roses/lilacs/ andthen S/red/blue/.put'
lilacs are blue


The `andthen` call reloads the `$_` topic variable. For more examples, see:

https://stackoverflow.com/questions/65066358/concatenating-s-in-raku 



HTH, Bill


It does.  Thank you!

Raku's regex's spoil me.  sed has to be
the editor from ...

Then again, I still use vi at times.


Re: run on regex line?

2024-01-20 Thread William Michels via perl6-users

> On Jan 19, 2024, at 23:49, ToddAndMargo via perl6-users 
>  wrote:
> 
> Hi All,
> 
> Can I do a run on line with a regex like I
> just did with sed?
> 
> $ zbarimg Screenshot.png | sed -e 's/.*?secret=//' -e 's/&.*//'
> 
> Usually I just do two lines in Raku.
> 
> Many thanks,
> -T


Hi Todd, 

Not that I am aware. The naive way is just to pipe them:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/' | raku -pe 's/red/blue/'
lilacs are blue 


The Raku way would be combining those two statements into one Raku call:

~$ echo 'roses are red' | raku -pe 's/roses/lilacs/; s/red/blue/'
lilacs are blue

#OR ("big-S" notation below)

~$ echo 'roses are red' | raku -ne 'S/roses/lilacs/ andthen S/red/blue/.put'
lilacs are blue


The `andthen` call reloads the `$_` topic variable. For more examples, see:

https://stackoverflow.com/questions/65066358/concatenating-s-in-raku

HTH, Bill