Created
September 5, 2024 17:37
-
-
Save aidos/44a9dfce3c16626e9e7834a83aed9188 to your computer and use it in GitHub Desktop.
Combine postgres log lines to put sql queries on a single line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/awk -f | |
# | |
# Handles combining log lines from postgres since the statements can have new lines in | |
# We identify the 2 classes of lines by the timestamp (or not) at the start of the line | |
# | |
# This makes grepping in the logs much easier | |
# reset buffer to current log line | |
/^[0-9]{4}-[0-9]{2}-[0-9]{2}/ { | |
print buffer | |
buffer = $0 | |
} | |
# line is continuation of previous statement, hold it for later | |
!/^[0-9]{4}-[0-9]{2}-[0-9]{2}/ { | |
buffer = buffer " " $0 | |
} | |
# print final statement | |
END { | |
print buffer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment