In running some scripts that update WordPress, the output of the scripts is logged to a file. Here is a relevant portion of the log file:
Downloading update from https://downloads.wordpress.org/plugin/adrotate.5.8.15.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the plugin...
Plugin updated successfully.
Downloading update from https://downloads.wordpress.org/plugin/cookie-notice.2.0.0.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the plugin...
Plugin updated successfully.
Downloading update from https://downloads.wordpress.org/plugin/google-site-kit.1.25.0.zip...
Unpacking the update...
Installing the latest version...
Removing the old version of the plugin...
Plugin updated successfully.
Disabling Maintenance mode...
+-----------------+-------------+-------------+---------+
| name | old_version | new_version | status |
+-----------------+-------------+-------------+---------+
| adrotate | 5.8.14 | 5.8.15 | Updated |
| cookie-notice | 1.3.2 | 2.0.0 | Updated |
| google-site-kit | 1.24.0 | 1.25.0 | Updated |
+-----------------+-------------+-------------+---------+
[32;1mSuccess:[0m Updated 3 of 3 plugins.
[32;1mSuccess:[0m Theme already updated.
What I want to do next is open, read, and extract a portion of that log file to write it to a separate file as-is. The critical piece I need is this table from the output above:
+-----------------+-------------+-------------+---------+
| name | old_version | new_version | status |
+-----------------+-------------+-------------+---------+
| adrotate | 5.8.14 | 5.8.15 | Updated |
| cookie-notice | 1.3.2 | 2.0.0 | Updated |
| google-site-kit | 1.24.0 | 1.25.0 | Updated |
+-----------------+-------------+-------------+---------+
So, what I'm doing is using
awk '/Disabling Maintenance mode...$/,/[32;1mSuccess:$/' logfile.txt
to attempt to grab that table. Unfortunately, with this awk
command, I seem to also get the Disabling Maintenance mode...
and [32;1mSuccess:
parts along with it. And those strings aren't reliably consistent enough to use them as proper start/end markers for awk
. The most accurate thing I can think of is the correct regex to grab just that table and nothing more.
The problem with the text-formatted table is that the length and width of it can vary depending on what the script is updating. The "name" column could have an item in it that's 50 characters long, for example, which makes the table wider. It could also have, like, 20 "rows". So I never know how many hyphens or pipe characters to count in regex or in some kind of loop.
I've tried various tutorials and also regex101.com to devise a pattern that will help me find this variable length/width pattern. But I'm making no progress. I'm not sure I know how to frame the problem correctly within regex syntax. All tutorials I'm reading are using "abc" and "xxx" as examples and this is so much more complex.
Can anyone help me figure out how to do this?