You can use grep
and sed
to do this:
pax> cat qq.in
/blah: Incorrect key file for table './accounts/headers.MYI'; try blah
/blah: Incorrect key file for table './pax/diablo.myi'; try blah
pax> grep 'Incorrect key file for ' qq.in | sed
-e 's/.*\.\//REPAIR TABLE /g'
-e 's/\//./'
-e 's/\.[Mm][Yy][Ii].*/;/g'
REPAIR TABLE accounts.headers;
REPAIR TABLE pax.diablo;
Note that I've put all those -e
sections on different lines for readability. They should be all on one line to test.
If your version of sed
supports case-insensitive searches (like the GNU one does), you can replace that last substitution with 's/\.myi.*/;/Ig'
.
To catch lines with different foramts is a bit trickier and will require all the formats to be known to avoid false positives. The following command will catch the alternate format as supplied in your comment:
pax> cat qq.in
/blah: Incorrect key file for table './accounts/headers.MYI'; try blah
/blah: Incorrect key file for table './linus/torvalds.myi'; try blah
/usr/local/mysql/bin/mysqld: Table './beta/search_data' is marked as crashed
allachan@IBM-L3F3936 ~
$ egrep 'Incorrect key|as crashed' qq.in | sed
-e "s/.*\.\//REPAIR TABLE /g"
-e "s/[\\.'].*/;/g"
-e "s/\//./"
REPAIR TABLE accounts.headers;
REPAIR TABLE linus.torvalds;
REPAIR TABLE beta.search_data;