One-liners to pretty print your MySQL configuration file

Some clever one-liners that print a neatly organised version of your MySQL configuration file without all the comments:

Perl
$ perl -ne 'm/^([^#][^\s=]+)\s*(=.*|)/ && printf("%-35s%s\n", $1, $2)' /etc/my.cnf

Awk
$ awk '! /^#/ && ! /^$/ {if($1 ~ /^\[/ ){gsub("\[","\n[",$1) };printf("%-35s%s %s\n",$1, $2, $3)}' /etc/my.cnf

Grep
$ egrep -v '^$|^#' /etc/my.cnf

Source: MySQL Performance Blog


Leave a Reply