一行中的两个变量
损坏的表条目记录在错误文件中,如下所示......
/usr/local/mysql/bin/mysqld:不正确 表的密钥文件 './accounts/headers.MYI';尝试 修复它
我想编写一个查询来修复此表。
修复表accounts.headers;
我需要做的是搜索“./”的第一个实例并选择第一个单词,即“accounts”,然后选择下一个单词“headers”。 现在使用这两个变量编写如上所示的语句。 我应该为此目的编写一个 Shell 脚本吗?
The corrupt table entry is logged in the error file something like this...
/usr/local/mysql/bin/mysqld: Incorrect
key file for table
'./accounts/headers.MYI'; try to
repair it
I want to write a query that will repair this table.
REPAIR TABLE accounts.headers;
What I need to do is search for the first instance of "./" and select the first word i.e. "accounts" and choose the next word "headers".
Now use these two variables to write a statement like shown above.
Should I write a Shell script for this purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
grep
和sed
来执行此操作:请注意,为了便于阅读,我已将所有这些
-e
部分放在不同的行上。它们应该全部在一根线上进行测试。如果您的
sed
版本支持不区分大小写的搜索(如 GNU 版本),您可以将最后一个替换替换为's/\.myi.*/;/Ig'.
捕获具有不同格式的行有点棘手,并且需要知道所有格式以避免误报。以下命令将捕获您的评论中提供的替代格式:
You can use
grep
andsed
to do this: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:
或者只是 sed
or just sed
以下正在做我期望它做的事情。但我对此不太满意,想知道更好的解决方案。
它将输出这样的语句...
; 之后的文本当mysql执行时会抛出错误,但我可以忽略它。
The following is doing what I expect it to do. But I am not too happy with it and will like to know better solution.
It will output the statements like this...
The text after ; will throw an error when mysql executes it, but I can ignore it.