Comments on: Useful sed / awk liners for MySQL https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql Blog by Shlomi Noach Thu, 19 Jan 2012 19:49:29 +0000 hourly 1 https://wordpress.org/?v=5.3.3 By: J. E. Aneiros https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-66739 Thu, 19 Jan 2012 19:49:29 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-66739 Only with Perl but it’s too long:

#!/usr/bin/perl

while () {
chomp;
if (/[^=# \t]+\s*=/) {
$l = $`;
$m = $&;
$r = $’;
$m =~ s/-/_/g;
print “$l$m$r\n”;
} else {
print “$_\n”;
}
}

]]>
By: J. E. Aneiros https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-66719 Thu, 19 Jan 2012 17:50:40 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-66719 This is almost a solution:

awk ‘/[^=]+\s*=\s*[^=]+/ { gsub(“-“, “_”, $1); print; next } { print }’ /etc/mysql/my.cnf

Still failing in the case of a comment line like

# ssl-ca=/etc/mysql/cacert.pem

Pretty cool the power of RE, eh?

]]>
By: J. E. Aneiros https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-66713 Thu, 19 Jan 2012 17:32:55 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-66713 I think the last script is not correct: it will changes comment lines in the form of –help to __help. Let see if I can found a different way to do it.

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-66707 Thu, 19 Jan 2012 16:43:40 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-66707 @Aneiros,

Wow, it’s been years since my last visit to Useless Use of Cat. Thanks!

Yes, technically the ‘cat’ is wasteful; but I actually like it the way it is: that way all the ‘sed’ invocations are more generic; they’re like real filters, whereas if the first ‘sed’ takes an input file, it’s less generic.
It’s a programmatic point of view; though I will not argue ove any contradicting opinion…

]]>
By: J. E. Aneiros https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-66705 Thu, 19 Jan 2012 16:36:54 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-66705 Now I see why the use of cat and pipes, it could be rewrite as

sed ‘/^#/d; /^$/d; s/[ \t]\+/ /g’ /etc/mysql/my.cnf

or even

sed ‘/^#|^$/d; s/[ \t]\+/ /g’ /etc/mysql/my.cnf.

]]>
By: J. E. Aneiros https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-66695 Thu, 19 Jan 2012 15:20:55 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-66695 Hi, thanks for the examples by I noticed that some of them could be rewrite without the useless cat command, avoiding Useless Use Of Cat: http://partmaps.org/era/unix/award.html.

]]>
By: varokism https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-45768 Sat, 09 Jul 2011 10:20:23 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-45768 tx shlomi ,

I found this one in my mailbox to found out updates in the slow log

cat dumslow.log | grep -i -n1 “update” | awk ‘{ print $2 }’ | grep -v “update” | awk ‘{ toto += $1 } END { print toto }’

]]>
By: Log Buffer #228, A Carnival of the Vanities for DBAs | The Pythian Blog https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-45693 Fri, 08 Jul 2011 08:12:09 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-45693 […] Shlomi Noach is listing some useful sed / awk liners to use with MySQL. […]

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-45525 Wed, 06 Jul 2011 09:36:29 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-45525 @nadavkav,
thanks, have added some.

]]>
By: nadavkav https://shlomi-noach.github.io/blog/mysql/useful-sed-awk-liners-for-mysql/comment-page-1#comment-45521 Wed, 06 Jul 2011 08:47:31 +0000 https://shlomi-noach.github.io/blog/?p=3685#comment-45521 Very useful commands.
Thanks!

Please consider adding them to:
http://www.commandlinefu.com/commands/browse

]]>