Using Raku (formerly known as Perl_6)
~$ raku -e 'my @a; for lines() {@a.push: $/.Int if .match(/<?after \"index\"\: \s > \d+ /) }; \
put ((1..10) (-) @a.Set).keys.sort;' index.txt
#OR
~$ raku -e 'my @a; for lines() {@a.push: $0.Int if .match(/<?after "index": \s > (\d+) /) };
put ((1..10) (-) @a.Set).keys.sort;' index.txt
Raku is a programming language in the Perl-family. It was released in 2015 as Perl_6, and renamed Raku in 2019. Consequently, you'll find many "Perl-isms" in Raku.
One interesting feature of Raku is Set semantics. Unicode as well as ASCII operators are available. In the code above, ASCII (-)
stands for Set difference (non-symmetric). You can also use Unicode:
∖
SET MINUS
Unicode: U+2216, UTF-8: E2 88 96
Sample Input (note max value is 100):
"index": 1
"index": 2
"index": 3
"index": 5
"index": 100
Sample Output (both code examples):
4 6 7 8 9 10
Caveat: It can be easy to confuse symmetric and non-symmetric Set operations. For example, with the code above if you reverse the order of sets and try the ASCII (^)
or Unicode ⊖
symmetric Set difference operator instead, you'll see a big difference (using 1..99
as the test range):
~$ cat index.txt | perl6 -e 'my @a = do for lines() {$/.Int if .match(/<?after \"index\"\: \s > \d+ /) }; put (@a.Set (-) (1..99)).keys.sort;'
100
~$ cat index.txt | perl6 -e 'my @a = do for lines() {$/.Int if .match(/<?after \"index\"\: \s > \d+ /) }; put (@a.Set (^) (1..99)).keys.sort;'
4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
https://docs.raku.org/language/setbagmix
https://raku.org
"index":
andnumber
? – Edgar Magallon Oct 17 '22 at 21:40cat
was unnecessary there: simplegrep index <file
orgrep index file
would be fine. – Toby Speight Oct 18 '22 at 06:44