Skip to content

Instantly share code, notes, and snippets.

@aidos
Created September 5, 2024 17:37
Show Gist options
  • Save aidos/44a9dfce3c16626e9e7834a83aed9188 to your computer and use it in GitHub Desktop.
Save aidos/44a9dfce3c16626e9e7834a83aed9188 to your computer and use it in GitHub Desktop.
Combine postgres log lines to put sql queries on a single line
#!/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