Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Last active January 24, 2020 02:25
Show Gist options
  • Select an option

  • Save JohnL4/00d3d97afb6ef4b2a6edd8f051dcc195 to your computer and use it in GitHub Desktop.

Select an option

Save JohnL4/00d3d97afb6ef4b2a6edd8f051dcc195 to your computer and use it in GitHub Desktop.
Grab a substring out of a string with Perl. But: Perl is the road to hell. Don't do it, mon.
cat edWebLog.txt | perl -e 'while (<>) { /caching service background update finished on thread \(id 21\) in ([0-9]+) ms/ && print "$1\n";}'
# Simpler:
echo abc | perl -n -e '/a(.)c/ && print "$1\n";'
# So, the first line becomes:
cat edWebLog.txt | perl -n -e '/caching service background update finished .* in ([0-9]+) ms/ && print "$1\n";'
# Note that the UNESCAPED parens are the capturing group. The escaped parens are just literal parens in the regex.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment