Showing posts with label awk. Show all posts
Showing posts with label awk. Show all posts

Monday, March 22, 2010

Using AWK to split syslog files by proc id

When troubleshooting a multi-threaded server it's sometimes nice to be able to split up the resulting log file by process making it a little bit easier to figure out what's going on. In this instance I'm splitting the log files from PostgreSQL by process ID which happens to be field 4.

# input format: 2010-01-25 15:41:46 PST [6534]: [30900-1] LOG:  duration: 0.243 ms  statement: SELECT ...

awk '{print > "substr($4, 2, length($4) - 3)"}' enroll.log

Using AWK to remove newlines from text

This is an AWK one liner that comes in handy. It will strip newlines from it's input replacing them with a single space. I often use it in conjunction with things such as svn, cut, sed and grep.

awk -v RS="\n" -v ORS=" " {print}