[Purdue-pm] a Raku Perl 6 regular expression one-liner
Mark Senn
mark at purdue.edu
Thu Dec 27 11:58:07 PST 2018
Here is a Raku (also known as Perl 6) one-liner to see what
groups user "fred" is in in a /etc/group file
perl6 -ne '/<<fred>>/ and .say' /etc/group
Each line of an /etc/group file has the format
groupname:password:groupid:members (user names separated by commas)
DESCRIPTION OF THE RAKU ONE-LINER:
WHAT DESCRIPTION SEE
perl6 we're running Raku Perl 6 [1]
-n don't print anything [2]
e do following expression for each line [2]
' start the expression
/ start a regex [3]
<< match a word start, same as «
>> match a word end, same as »
/ end a regex
and if regex matches do what's after "and"
.say print $_ followed by a newline, same as $_.say
' end the expression
/etc/group the file to read
[1] https://colabti.org/irclogger/irclogger_log/perl6?date=2018-10-25#l584
[2] https://perl6.online/2018/12/20/using-command-line-options-in-perl-6-one-liners/
[3] Regexes were formerly known as regular expressions.
https://docs.perl6.org/language/regexes
THE FINE PRINT
<<fred>> will not match 'winifred'.
The above one liner will match group names, passwords, or gids
containing 'fred'. Change '/<<fred>>/' to '/.*:<<fred>>/'.
The '.*:' matches everything up to and including the last colon.
-mark
More information about the Purdue-pm
mailing list