Using Raku (formerly known as Perl_6)
raku -ne '.put unless .grep: all(/def/ , /jkl/);'
OR
raku -ne '.put if .grep: { !/def/ || !/jkl/ };'
OR (Raku equivalent of @terdon's Perl5 code):
raku -ne '.put unless /def/ && /jkl/;'
OR
raku -ne '/def/ && /jkl/ || .put;'
OR
raku -ne '(/def/ && /jkl/) ?? {next} !! .put'
Sample Input:
1. abc def ghi
2. def ghi jkl
3. jkl mno pqr
4. jkl def stu
5. vwx yza bcd
Sample Output:
1. abc def ghi
3. jkl mno pqr
5. vwx yza bcd
Briefly, the first two answers using the -ne
(non-autoprinting) linewise flag along with Raku's grep
routine. The next three answers are the Raku equivalent of @terdon's Perl(5) answers.
The first two (grep
) lines of code are interesting in that they use two different mechanisms: the first uses an all
junction (often called on Sets within Raku), while in the second example grep
is run on a {}
code block, which boolifies to a True/False.
A nice variation on the first two (grep
) results is taking advantages of extra parameters (:k
, :v
, :kv
, :p
) available in the grep
routine. For example, simply adding the :p
pairs ('adverbial' parameter) instructs the code to output results as numbered pairs:
raku -ne '.put if .grep( { !/def/ || !/jkl/ }, :p );'
Sample Output (with index):
0 => 1. abc def ghi
2 => 3. jkl mno pqr
4 => 5. vwx yza bcd
https://raku.org