[Purdue-pm] a Raku Perl 6 regular expression one-liner
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 
-n don't print anything 
e do following expression for each line 
' start the expression
/ start a regex 
<< 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
 Regexes were formerly known as regular expressions.
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.
More information about the Purdue-pm