Using Raku (formerly known as Perl_6)
~$ raku -e 'put $<> if m{ "Artifacts were created:" \n <( \N* } for lines.join: "\n";' file
#OR
~$ raku -e 'put $0 if m{ "Artifacts were created:" \n (\N*) } for lines.join: "\n";' file
If the OP is willing to consider Perl-family Programming languages, Raku is a good choice. Above, the input file is read-in linewise, and joined with \n
newlines. The target "Artifacts were created:" \n
is identified, after which the match is sought.
In the first example, Raku's capture markers <( … )>
are used to drop the "Artifacts..." line from the match object, and the remaining capture is output
using the $<>
(or synonymous $/
) match variable (subject to an if
conditional). Actually, for this problem only one capture marker <(
is needed.
In the second example, parentheses are used to capture a portion of the match into match-variable $<>.[0]
which is the same as match-variable $/.[0]
which is the same as $0
. This $0
capture is output
subject to an if
conditional.
Sample Input:
10:28:48 2022-09-15T15:28:36Z: Creating tar ball for build artifacts
--
10:28:53 --> Build complete: Artifacts were created:
file: build-1.tar.gz
Sample Output:
file: build-1.tar.gz
There really are quite a number of built-in character classes in Raku, so the characteristic [\N* \n]
pattern (zero-or-more non-newline characters followed by a newline) can be replicated for many other patterns (e.g. [\S* \s]
or [\d* \D]
, etc.).
https://docs.raku.org/language/regexes
https://raku.org