Awk: Difference between revisions
adds an awk idiom to output ls into tsv |
adds recipes for grepping the line AFTER a matching pattern |
||
| Line 220: | Line 220: | ||
# containing the regex | # containing the regex | ||
awk '/regex/{getline;print}' | awk '/regex/{getline;print}' | ||
# someone said somewhere that getline can pose problems.... dunno exactly what/why but here's an alternate | |||
# This prints the 5th field of the line following the regex | |||
# Then pipes it to grep with perl-compatible regex to use look-behind and look-ahead assertions to print the contents inside parenthesis | |||
# so given an error log that contains the following two lines (repeatedly), and you want to extract the names of the tables | |||
# Operation failed with exitcode 3 | |||
# 12:09:54 AM Dumping wordpress (log_civicrm_extension) | |||
awk 'f{print $5;f=0} /Operation failed with exitcode/{f=1}' /tmp/mysqldump.error.log | sort | grep -P -o '(?<=\().*(?=\))' | |||
## Admittedly this is more complex than just a couple greps!! | |||
# grep -A1 /Operation failed with exitcode/ /tmp/mysqldump.error.log | sort | grep -P -o '(?<=\().*(?=\))' | |||
# grep for AAA and BBB and CCC (in any order) | # grep for AAA and BBB and CCC (in any order) | ||