{"id":20550207,"url":"https://github.com/dnmfarrell/perl6-one-liners","last_synced_at":"2025-10-27T06:02:36.342Z","repository":{"id":23208379,"uuid":"26565239","full_name":"dnmfarrell/Perl6-One-Liners","owner":"dnmfarrell","description":"Look what you can do at the terminal! A collection of Perl6 one liners","archived":false,"fork":false,"pushed_at":"2017-02-23T03:25:01.000Z","size":65,"stargazers_count":164,"open_issues_count":16,"forks_count":30,"subscribers_count":38,"default_branch":"master","last_synced_at":"2025-07-06T16:06:34.842Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl6","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dnmfarrell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-13T01:48:42.000Z","updated_at":"2023-08-06T21:29:49.000Z","dependencies_parsed_at":"2022-09-12T17:25:58.937Z","dependency_job_id":null,"html_url":"https://github.com/dnmfarrell/Perl6-One-Liners","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dnmfarrell/Perl6-One-Liners","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FPerl6-One-Liners","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FPerl6-One-Liners/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FPerl6-One-Liners/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FPerl6-One-Liners/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dnmfarrell","download_url":"https://codeload.github.com/dnmfarrell/Perl6-One-Liners/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FPerl6-One-Liners/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281222704,"owners_count":26464003,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T02:23:49.780Z","updated_at":"2025-10-27T06:02:36.316Z","avatar_url":"https://github.com/dnmfarrell.png","language":"Perl6","funding_links":[],"categories":[],"sub_categories":[],"readme":"Perl 6 One Liners\n=================\n\nThis book is a work in progress. I hope you find it interesting, maybe even useful! If you would like to contribute, feedback, issues and new or improved regexes are all welcome!\n\n\nAUTHOR\n------\n\nDavid Farrell [PerlTricks.com](http://perltricks.com)\n\n\nVERSION\n-------\n\nVersion 0.01\n\n\nLICENSE\n-------\n\nFreeBSD - see LICENSE\n\n\nCONTRIBUTORS\n------------\n\n* Alexander Moquin\n* Bruce Gray\n* Cale\n* Carl Mäsak\n* David H. Adler\n* FROGGS\n* Helmut Wollmersdorfer\n* Hugh Simpson\n* japhb\n* Larry Wall\n* Mathieu Gagnon\n* Matt Oates\n* Moritz Lenz\n* Mouq\n* Salve J Nilsen\n* Sam S\n* Skids\n* timotimo\n\n\nTHANKS\n------\n\nInspired by Peteris Krumins Perl 5 examples [file](http://www.catonmat.net/download/perl1line.txt). He literally wrote the [book](http://www.nostarch.com/perloneliners) on Perl 5 one liners.\n\nThe wonderful folks on #Perl6 [irc](http://webchat.freenode.net/?channels=perl6\u0026nick=).\n\n\nCONTENTS\n--------\n\n1.  [Introduction](#introduction)\n2.  [Tutorial](#tutorial)\n3.  [File Spacing](#file-spacing)\n4.  [Line Numbering](#line-numbering)\n5.  [Calculations](#calculations)\n6.  [String Creation and Array Creation](#string-creation-and-array-creation)\n7.  [Text Conversion and Substitution](#text-conversion-and-substitution)\n8.  [Text Analysis](#text-analysis)\n9.  [Selective Line Printing](#selective-line-printing)\n10. [Data Transformation With Pipes](data-transformation-with-pipes) (in progress)\n11. [WWW](#www) (in progress)\n12. [Converting for Windows](#converting-for-windows)\n\n\nINTRODUCTION\n------------\n\nOne thing that sets Perl apart from other languages is the ability to write small programs in a single line of code, known as a \"one liner\". It's often faster to type a program directly into the terminal than to write a throwaway script. And one liners are powerful too; they're fully fledged programs which can load external libraries but also integrate into the terminal. You can pipe data in or out of a one liner.\n\nLike Perl 5, Perl 6 supports one liners. And just like Perl 6 cleaned up Perl 5's warts elsewhere, the one liner syntax is also better. It's cleaner with fewer special variables and options to memorize. This book provides many useful examples of Perl 6 one liners that can do everything from finding duplicate lines in a file to running a web server. Although Perl 6 has fewer special variables, because of its advanced object oriented syntax most of the one liners are shorter in Perl 6 than their Perl 5 equivalent.\n\nThis book can be read in a number of ways. If you're new to one liners, start with the [tutorial](#tutorial). It walks you through the core concepts of a one liner; don't worry - it's really very simple once you get the hang of it. If you're familiar with Perl, Bash or Sed/Awk, you can probably get stuck in to the examples right away. Feel free to skim and scan the material for whatever piques your interest. If you don't understand some code, try it out in the terminal! Included in this repo is the ubiquitous `example.txt` file which is used in many of the one liners.\n\nProgramming with one liners is just one paradigm that Perl 6 excels in. There's a beauty in the brevity of this code, but whilst you're learning a productive skill, remember that you're also learning the ropes of a powerful new programming language. Check out the [perl6.org](http://perl6.org) website for the official documentation.\n\n\nTUTORIAL\n--------\n\nTo get started with one liners, all you really need to understand is the `-e` option. This tells Perl to execute what follows as a program. For example:\n\n    perl6 -e 'say \"Hello, World!\"'\n\nLet's step through this code. `perl6` invokes the Perl 6 program, `-e` tells Perl 6 to execute and `'say \"Hello, World!\"'` is the program. Every program must be surrounded in single quotes (except on Windows, see [Converting for Windows](#converting-for-windows)). To run the one-liner, just type it into the terminal:\n\n    \u003e perl6 -e 'say \"Hello, World!\"'\n    Hello, World!\n\nIf you want to load a file, just add the path to the file after the program code:\n\n    perl6 -e 'for (lines) { say $_ }' /path/to/file.txt\n\nThis program prints every line in `/path/to/file.txt`. You may know that `$_` is the default variable, which in this case is the current line being looped through. `lines` is a list that is automatically created for you whenever you pass a filepath to a one-liner. Now let's re-write that one liner, step-by-step. These are all equivalent:\n\n    perl6 -e 'for (lines) { say $_ }' /path/to/file.txt\n    perl6 -e 'for (lines) { $_.say }' /path/to/file.txt\n    perl6 -e 'for (lines) { .say }' /path/to/file.txt\n    perl6 -e '.say for (lines)' /path/to/file.txt\n    perl6 -e '.say for lines' /path/to/file.txt\n\nJust like `$_` is the default variable, methods called on the default variable can omit the variable reference. They become default methods. So `$_.say` becomes `.say`. This brevity pays off with one liners - it's less typing!\n\nThe `-n` option changes the behavior of the program: it executes the code once for every line of the file. So uppercase and print every line of `/path/to/file.txt` you can type:\n\n    perl6 -ne '.uc.say' /path/to/file.txt\n\nThe `-p` option is just like `-n` except that it will automatically print `$_`. So another way we could uppercase a file would be:\n\n    perl6 -pe '$_ = .uc' /path/to/file.txt\n\nOr two shorter versions that do the same thing:\n\n    perl6 -pe '.=uc' /path/to/file.txt\n    perl6 -pe .=uc /path/to/file.txt\n\nIn the second example we were able to completely remove the surrounding single quotes. This is a rare scenario, but in the event your one liner has no spaces and no sigils or quotes in it, you can usually remove the outer quotes.\n\nThe `-n` and `-p` options are really useful. There are lots of example one-liners that use them in this book.\n\nThe final thing you should know is how to load a module. This is really powerful as you can extend Perl 6's capabilities by importing external libraries. The `-M` switch stands for load module:\n\n    perl6 -M URI::Encode -e 'say uri_encode(\"example.com/10 ways to crush it with Perl 6\")'\n\nThis: `-M URI::Encode` loads the URI::Encode module, which exports the `uri_encode` subroutine. You can use `-M` more than once if you want to load more than one module:\n\n    perl6 -M URI::Encode -M URI -e '\u003cyour code here\u003e'\n\nWhat if you have a local module, that is not installed yet? Easy, just pass use the `-I` switch to include the directory:\n\n    perl6 -I lib -M URI::Encode -e '\u003cyour code here\u003e'\n\nNow Perl 6 will search for `URI::Encode` in `lib` as well as the standard install locations.\n\nTo get a list of Perl 6 command line switches, use the `-h` option for help:\n\n    perl6 -h\n\nThis prints a nice summary of the available options.\n\n\nFILE SPACING\n------------\n\nDouble space a file\n\n    perl6 -pe '$_ ~= \"\\n\"' example.txt\n\nN-space a file (e.g. quadruple space)\n\n    perl6 -pe '$_ ~= \"\\n\" x 4' example.txt\n\nAdd a blank line before every line\n\n    perl6 -pe 'say \"\"' example.txt\n\nRemove all blank lines\n\n    perl6 -ne '.say if /\\S/' example.txt\n    perl6 -ne '.say if .chars' example.txt\n\nRemove all consecutive blank lines, leaving just one\n\n    perl6 -e '$*ARGFILES.slurp.subst(/\\n+/, \"\\n\\n\", :g).say' example.txt\n\n\nLINE NUMBERING\n--------------\n\nNumber all lines in a file\n\n    perl6 -ne 'say \"{++$} $_\"' example.txt\n    perl6 -ne 'say $*ARGFILES.lines.kv ~ \" $_\"' example.txt\n\nNumber only non-empty lines in a file\n\n    perl6 -pe '$_ = \"{++$} $_\" if /\\S/' example.txt\n\nNumber all lines but print line numbers only for non-empty lines\n\n    perl6 -pe '$_ = $*ARGFILES.lines.kv ~ \" $_\" if /\\S/' example.txt\n\nPrint the total number of lines in a file (emulate wc -l)\n\n    perl6 -e 'say lines.elems' example.txt\n    perl6 -e 'say lines.Int' example.txt\n    perl6 -e 'lines.Int.say' example.txt\n\nPrint the number of non-empty lines in a file\n\n    perl6 -e 'lines.grep(/\\S/).elems.say' example.txt\n\nPrint the number of empty lines in a file\n\n    perl6 -e 'lines.grep(/^\\s*$/).elems.say' example.txt\n\n\nCALCULATIONS\n------------\n\nCheck if a number is a prime\n\n    perl6 -e 'say \"7 is prime\" if 7.is-prime'\n\nPrint the sum of all the fields on a line\n\n    perl6 -ne 'say [+] .split(\"\\t\")'\n\nPrint the sum of all the fields on all lines\n\n    perl6 -e 'say [+] lines.split(\"\\t\")'\n\nShuffle all fields on a line\n\n    perl6 -ne '.split(\"\\t\").pick(*).join(\"\\t\").say'\n\nFind the lexically minimum element on a line\n\n    perl6 -ne '.split(\"\\t\").min.say'\n\nFind the lexically minimum element over all the lines\n\n    perl6 -e 'lines.split(\"\\t\").min.say'\n\nFind the lexically maximum element on a line\n\n    perl6 -ne '.split(\"\\t\").max.say'\n\nFind the lexically maximum element over all the lines\n\n    perl6 -e 'lines.split(\"\\t\").max.say'\n\nFind the numerically minimum element on a line\n\n    perl6 -ne '.split(\"\\t\")».Numeric.min.say'\n\nFind the numerically  maximum element on a line\n\n    perl6 -ne '.split(\"\\t\")».Numeric.max.say'\n\nReplace each field with its absolute value\n\n    perl6 -ne '.split(\"\\t\").map(*.abs).join(\"\\t\").say'\n\nFind the total number of letters on each line\n\n    perl6 -ne '.chars.say' example.txt\n\nFind the total number of words on each line\n\n    perl6 -ne '.words.elems.say' example.txt\n\nFind the total number of elements on each line, split on a comma\n\n    perl6 -ne '.split(\",\").elems.say' example.txt\n\nFind the total number of fields (words) on all lines\n\n    perl6 -e 'say lines.split(\"\\t\").elems' #fields\n    perl6 -e 'say lines.words.elems' example.txt #words\n\nPrint the total number of fields that match a pattern\n\n    perl6 -e 'say lines.split(\"\\t\").comb(/pattern/).elems' #fields\n    perl6 -e 'say lines.words.comb(/pattern/).elems' #words\n\nPrint the total number of lines that match a pattern\n\n    perl6 -e 'say lines.grep(/in/).elems'\n\nPrint the number PI to n decimal places (e.g. 10)\n\n    perl6 -e 'say pi.fmt(\"%.10f\");'\n\nPrint the number PI to 15 decimal places\n\n    perl6 -e 'say π'\n\nPrint the number E to n decimal places (e.g. 10)\n\n    perl6 -e 'say e.fmt(\"%.10f\");'\n\nPrint the number E to 15 decimal places\n\n    perl6 -e 'say e'\n\nPrint UNIX time (seconds since Jan 1, 1970, 00:00:00 UTC)\n\n    perl6 -e 'say time'\n\nPrint GMT (Greenwich Mean Time) and local computer time\n\n    perl6 -MDateTime::TimeZone -e 'say to-timezone(\"GMT\",DateTime.now)'\n    perl6 -e 'say DateTime.now'\n\nPrint local computer time in H:M:S format\n\n    perl6 -e 'say DateTime.now.map({$_.hour, $_.minute, $_.second.round}).join(\":\")'\n\nPrint yesterday's date\n\n    perl6 -e 'say DateTime.now.earlier(:1day)'\n\nPrint date 14 months, 9 days and 7 seconds ago\n\n    perl6 -e 'say DateTime.now.earlier(:14months).earlier(:9days).earlier(:7seconds)'\n\nPrepend timestamps to stdout (GMT, localtime)\n\n    tail -f logfile | perl6 -MDateTime::TimeZone -ne 'say to-timezone(\"GMT\",DateTime.now) ~ \"\\t$_\"'\n    tail -f logfile | perl6 -ne 'say DateTime.now ~ \"\\t$_\"'\n\nCalculate factorial of 5\n\n    perl6 -e 'say [*] 1..5'\n\nCalculate greatest common divisor\n\n    perl6 -e 'say [gcd] @list_of_numbers'\n\nCalculate GCM of numbers 20 and 35 using Euclid's algorithm\n\n    perl6 -e 'say (20, 35, *%* ... 0)[*-2]'\n\nCalculate least common multiple (LCM) of 20 and 35\n\n    perl6 -e 'say 20 lcm 35'\n\nCalculate LCM of 20 and 35 using Euclid's algorithm: `n*m/gcd(n,m)`\n\n    perl6 -e 'say 20 * 35 / (20 gcd 35)'\n\nGenerate 10 random numbers between 5 and 15 (excluding 15)\n\n    perl6 -e '.say for (5..^15).roll(10)'\n\nFind and print all permutations of a list\n\n    perl6 -e 'say .join for [1..5].permutations'\n\nGenerate the power set\n\n    perl6 -e '.say for \u003c1 2 3\u003e.combinations'\n\nConvert an IP address to unsigned integer\n\n    perl6 -e 'say :256[\"127.0.0.1\".comb(/\\d+/)]'\n    perl6 -e 'say +\":256[{q/127.0.0.1/.subst(:g,/\\./,q/,/)}]\"'\n    perl6 -e 'say Buf.new(+«\"127.0.0.1\".split(\".\")).unpack(\"N\")'\n\nConvert an unsigned integer to an IP address\n\n    perl6 -e 'say join \".\", @(pack \"N\", 2130706433)'\n    perl6 -e 'say join \".\", map { ((2130706433+\u003e(8*$_))+\u00260xFF) }, (3...0)'\n\nSTRING CREATION AND ARRAY CREATION\n----------------------------------\n\nGenerate and print the alphabet\n\n    perl6 -e '.say for \"a\"..\"z\"'\n\nGenerate and print all the strings from \"a\" to \"zz\"\n\n    perl6 -e '.say for \"a\"..\"zz\"'\n\nConvert a integer to hex\n\n    perl6 -e 'say 255.base(16)'\n    perl6 -e 'say sprintf(\"%x\", 255)'\n\nPrint an int to hex translation table\n\n    perl6 -e 'say sprintf(\"%3i =\u003e %2x\", $_, $_) for 0..255'\n\nPercent encode an integer\n\n    perl6 -e 'say sprintf(\"%%%x\", 255)'\n\nGenerate a random 10 a-z character string\n\n    perl6 -e 'print roll 10, \"a\"..\"z\"'\n    perl6 -e 'print roll \"a\"..\"z\": 10'\n\nGenerate a random 15 ASCII Character password\n\n    perl6 -e 'print roll 15, \"0\"..\"z\"'\n    perl6 -e 'print roll \"0\"..\"z\": 15'\n\nCreate a string of specific length\n\n    perl6 -e 'print \"a\" x 50'\n\nGenerate and print an array of even numbers from 1 to 100\n\n    perl6 -e '(1..100).grep(* %% 2).say'\n\nFind the length of the string\n\n    perl6 -e '\"storm in a teacup\".chars.say'\n\nFind the number of elements in an array\n\n    perl6 -e 'my @letters = \"a\"..\"z\"; @letters.Int.say'\n\n\nTEXT CONVERSION AND SUBSTITUTION\n--------------------------------\n\nROT 13 a file\n\n    perl6 -pe 'tr/A..Za..z/N..ZA..Mn..za..m/' example.txt\n\nBase64 encode a string\n\n    perl6 -MMIME::Base64 -ne 'print MIME::Base64.encode-str($_)' example.txt\n\nBase64 decode a string\n\n    perl6 -MMIME::Base64 -ne 'print MIME::Base64.decode-str($_)' base64.txt\n\nURL-escape a string\n\n    perl6 -MURI::Encode -le 'say uri_encode($string)'\n\nURL-unescape a string\n\n    perl6 -MURI::Encode -le 'say uri_decode($string)'\n\nHTML-encode a string\n\n    perl6 -MHTML::Entity -e 'print encode-entities($string)'\n\nHTML-decode a string\n\n    perl6 -MHTML::Entity -e 'print decode-entities($string)'\n\nConvert all text to uppercase\n\n    perl6 -pe '.=uc' example.txt\n    perl6 -ne 'say .uc' example.txt\n\nConvert all text to lowercase\n\n    perl6 -pe '.=lc' example.txt\n    perl6 -ne 'say .lc' example.txt\n\nUppercase only the first word of each line\n\n    perl6 -ne 'say s/(\\w+){}/{$0.uc}/' example.txt\n\nInvert the letter case\n\n    perl6 -pe 'tr/a..zA..Z/A..Za..z/' example.txt\n    perl6 -ne 'say tr/a..zA..Z/A..Za..z/.after' example.txt\n\nCamel case each line\n\n    perl6 -ne 'say .wordcase' example.txt\n\nStrip leading whitespace (spaces, tabs) from the beginning of each line\n\n    perl6 -ne 'say .trim-leading' example.txt\n\nStrip trailing whitespace (space, tabs) from the end of each line\n\n    perl6 -ne 'say .trim-trailing' example.txt\n\nStrip whitespace from the beginning and end of each line\n\n    perl6 -ne 'say .trim' example.txt\n\nConvert UNIX newlines to DOS/Windows newlines\n\n    perl6 -ne 'print .subst(/\\n/, \"\\r\\n\")' example.txt\n\nConvert DOS/Windows newlines to UNIX newlines\n\n    perl6 -ne 'print .subst(/\\r\\n/, \"\\n\")' example.txt\n\nFind and replace all instances of \"ut\" with \"foo\" on each line\n\n    perl6 -pe 's:g/ut/foo/' example.txt\n\nFind and replace all instances of \"ut\" with \"foo\" on each line that contains \"lorem\"\n\n    perl6 -pe 's:g/ut/foo/ if /Lorem/' example.txt\n\nConvert a file to JSON\n\n    perl6 -M JSON::Tiny -e 'say to-json(lines)' example.txt\n\nPick 5 random words from each line of a file\n\n    perl6 -ne 'say .words.pick(5)' example.txt\n\n\nTEXT ANALYSIS\n-------------\n\nPrint n-grams of a string\n\n    perl6 -e 'my $n=2; say \"banana\".comb.rotor($n =\u003e 1 - $n)».join()'\n\nPrint unique n-grams\n\n    perl6 -e 'my $n=2; say \"banana\".comb.rotor($n =\u003e 1 - $n)».join().Set.sort'\n\nPrint occurrence counts of n-grams\n\n    perl6 -e 'my $n=2; say \"banana\".comb.rotor($n =\u003e 1 - $n)».join().Bag.sort.join(\"\\n\")'\n\nPrint occurrence counts of words (1-grams)\n\n    perl6 -e 'say lines[0].words.join().Bag.sort.join(\"\\n\")' example.txt\n\nPrint Dice similarity coefficient based on sets of 1-grams\n\n    perl6 -e 'my $a=\"banana\".comb;my $b=\"anna\".comb;say ($a (\u0026) $b)/($a.Set + $b.Set)'\n\nPrint Jaccard similarity coefficient based on 1-grams\n\n    perl6 -e 'my $a=\"banana\".comb;my $b=\"anna\".comb;say ($a (\u0026) $b) / ($a (|) $b)'\n\nPrint overlap coefficient based on 1-grams\n\n    perl6 -e 'my $a=\"banana\".comb;my $b=\"anna\".comb;say ($a (\u0026) $b)/($a.Set.elems,$b.Set.elems).min'\n\nPrint cosine similarity based on 1-grams\n\n    perl6 -e 'my $a=\"banana\".comb;my $b=\"anna\".comb;say ($a (\u0026) $b)/($a.Set.elems.sqrt*$b.Set.elems.sqrt)'\n\nBuild an index of characters within a string and print it\n\n    perl6 -e 'say {}.push: %(\"banana\".comb.pairs).invert'\n \nBuild an index of words within a line and print it\n\n    perl6 -e '({}.push: %(lines[0].words.pairs).invert).sort.join(\"\\n\").say' example.txt\n\n\nSELECTIVE LINE PRINTING\n-----------------------\n\nPrint the first line of a file (emulate head -1)\n\n    perl6 -ne '.say;exit' example.txt\n    perl6 -e 'lines[0].say' example.txt\n    perl6 -e 'lines.shift.say' example.txt\n\nPrint the first 10 lines of a file (emulate head -10)\n\n    perl6 -pe 'exit if ++$ \u003e 10' example.txt\n    perl6 -ne '.say if ++$ \u003c 11' example.txt\n\nPrint the last line of a file (emulate tail -1)\n\n    perl6 -e 'lines.pop.say' example.txt\n\nPrint the last 5 lines of a file (emulate tail -5)\n\n    perl6 -e '.say for lines[*-5..*]' example.txt\n\nPrint only lines that contain vowels\n\n    perl6 -ne '/\u003c[aeiou]\u003e/ \u0026\u0026 .print' example.txt\n\nPrint lines that contain all vowels\n\n    perl6 -ne '.say if .comb (\u003e=) \u003ca e i o u\u003e' example.txt\n    perl6 -ne '.say if .comb ⊇ \u003ca e i o u\u003e' example.txt\n\nPrint lines that are 80 chars or longer\n\n    perl6 -ne '.print if .chars \u003e= 80' example.txt\n    perl6 -ne '.chars \u003e= 80 \u0026\u0026 .print' example.txt\n\nPrint only line 2\n\n    perl6 -ne '.print if ++$ == 2' example.txt\n\nPrint all lines except line 2\n\n    perl6 -pe 'next if ++$ == 2' example.txt\n\nPrint all lines 1 to 3\n\n    perl6 -ne '.print if (1..3).any == ++$' example.txt\n\nPrint all lines between two regexes (including lines that match regex)\n\n    perl6 -ne '.print if /^Lorem/../laborum\\.$/' example.txt\n\nPrint the length of the longest line\n\n    perl6 -e 'say lines.max.chars' example.txt\n    perl6 -ne 'state $l=0; $l = .chars if .chars \u003e $l;END { $l.say }' example.txt\n\nPrint the longest line\n\n    perl6 -e 'say lines.max' example.txt\n    perl6 -e 'my $l=\"\"; for (lines) {$l = $_ if .chars \u003e $l.chars};END { $l.say }' example.txt\n\nPrint all lines that contain a number\n\n    perl6 -ne '.say if /\\d/' example.txt\n    perl6 -e '.say for lines.grep(/\\d/)' example.txt\n    perl6 -ne '/\\d/ \u0026\u0026 .say' example.txt\n    perl6 -pe 'next if ! $_.match(/\\d/)' example.txt\n\nFind all lines that contain only a number\n\n    perl6 -ne '.say if /^\\d+$/' example.txt\n    perl6 -e '.say for lines.grep(/^\\d+$/)' example.txt\n    perl6 -ne '/^\\d+$/ \u0026\u0026 .say' example.txt\n    perl6 -pe 'next if ! $_.match(/^\\d+$/)' example.txt\n\nPrint every even line\n\n    perl6 -ne '.say if ++$ %% 2' example.txt\n\nPrint every odd line\n\n    perl6 -ne '.say if ++$ !%% 2' example.txt\n\nPrint all lines that repeat\n\n    perl6 -ne 'state %l;.say if ++%l{$_}==2' example.txt\n\nPrint unique lines\n\n    perl6 -ne 'state %l;.say if ++%l{$_}==1' example.txt\n\nPrint the first field (word) of every line (emulate cut -f 1 -d ' ')\n\n    perl6 -ne '.words[0].say' example.txt\n\n\nDATA TRANSFORMATION WITH PIPES\n------------------------------\n\nPerl 6 programs integrate straight into the command line. You can pipe data in-to and out-of a one liner by using the pipe `|` character. For piping data in, Perl 6 automatically sets STDIN to `$*IN`. Just like with files, data piped in can be looped through using `-n` and is also available in `lines`. To pipe data out of a one liner just use `print` or `say`.\n\nJSON-encode a list of all files in the current directory\n\n    ls | perl6 -M JSON::Tiny -e 'say to-json(lines)'\n\nPrint a random sample of approx 5% of lines in a file\n\n    perl6 -ne '.say if 1.rand \u003c= 0.05' /usr/share/dict/words\n\nColor conversion, HTML to RGB\n\n    echo \"#ffff00\" | perl6 -ne '.comb(/\\w\\w/).map({:16($_)}).say'\n\nColor conversion, RGB to HTML\n\n    echo \"#ffff00\" | perl6 -ne '.comb(/\\w\\w/).map({:16($_)}).say'\n\nWWW\n---\n\nDownload a webpage\n\n    perl6 -M HTTP::UserAgent -e 'say HTTP::UserAgent.new.get(\"google.com\").content'\n\nDownload a webpage and strip out the HTML\n\n    wget -O - \"http://perl6.org\" | perl6 -ne 's:g/\\\u003c.+?\\\u003e//.say'\n\nDownload a webpage, strip out and decode the HTML\n\n    wget -O - \"http://perl6.org\" | perl6 -MHTML::Strip -ne 'strip_html($_).say'\n\nLaunch a simple web server\n\n    perl6 -M HTTP::Server::Simple -e 'HTTP::Server::Simple.new.run'\n\n\nCONVERTING FOR WINDOWS\n----------------------\n\nRunning one liners on Windows is a piece of cake once you know the rules of the road. One liners work on both cmd.exe and PowerShell. The cardinal rule is: replace the outer single-quotes with double quotes and use the interpolated quoting operator `qq//` for quoting strings inside a one liner. For non-interpolated quoting, you can use single-quotes. Let's look at some examples.\n\nHere's a simple one liner to print the time:\n\n    perl6 -e 'say DateTime.now'\n\nTo run on Windows, we just replace the single quotes with double quotes:\n\n    perl6 -e \"say DateTime.now\"\n\nThis one liner appends a newline to every line in a file, using an interpolated string:\n\n    perl6 -pe '$_ ~= \"\\n\"' example.txt\n\nOn Windows this should be written as:\n\n    perl6 -pe \"$_ ~= qq/\\n/\" example.txt\n\nIn this case we want to interpolate `\\n` as a newline and not literally add a backslash and an \"n\" to the line, so we have to use `qq`. But you can usually use single-quotes within a one liner so:\n\n    perl6 -e 'say \"Hello, World!\"'\n\nOn Windows can be written as:\n\n    perl6 -e \"say 'hello, World!'\"\n\nSimple output redirection works like it does on Unix-based systems. This one liner prints an ASCII character index table to a file using `\u003e`:\n\n    perl6 -e \"say .chr ~ ' ' ~ $_ for 0..255\" \u003e ascii_codes.txt\n\nWhen using `\u003e` if the file doesn't exist, it will be created. If the file does exist, it will be overwritten. If you'd rather append to a file, use `\u003e\u003e` instead.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnmfarrell%2Fperl6-one-liners","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdnmfarrell%2Fperl6-one-liners","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnmfarrell%2Fperl6-one-liners/lists"}