通过 mysql 模板进行 grep 搜索
我正在尝试通过 grep 在 filenmae 中搜索,但我遇到了一些问题..
我想通过模板搜索
'apple banana'
Find rows that contain at least one of the two words.
'+apple +juice'
Find rows that contain both words.
'+apple macintosh'
Find rows that contain the word “apple”, but rank rows higher if they also contain “macintosh”.
'+apple -macintosh'
Find rows that contain the word “apple” but not “macintosh”.
'+apple ~macintosh'
Find rows that contain the word “apple”, but if the row also contains the word “macintosh”, rate it lower than if row does not. This is “softer” than a search for '+apple -macintosh', for which the presence of “macintosh” causes the row not to be returned at all.
'+apple +(>turnover <strudel)'
Find rows that contain the words “apple” and “turnover”, or “apple” and “strudel” (in any order), but rank “apple turnover” higher than “apple strudel”.
'apple*'
Find rows that contain words such as “apple”, “apples”, “applesauce”, or “applet”.
'"some words"'
Find rows that contain the exact phrase “some words” (for example, rows that contain “some words of wisdom” but not “some noise words”). Note that the “"” characters that enclose the phrase are operator characters that delimit the phrase. They are not the quotation marks that enclose the search string itself.
第一条规则: grep "apple\|banana" filename
其他规则导致问题。 请帮助我,抱歉英语不好。
I'm trying search in filenmae by grep, but I have a some problem..
I want search by templates
'apple banana'
Find rows that contain at least one of the two words.
'+apple +juice'
Find rows that contain both words.
'+apple macintosh'
Find rows that contain the word “apple”, but rank rows higher if they also contain “macintosh”.
'+apple -macintosh'
Find rows that contain the word “apple” but not “macintosh”.
'+apple ~macintosh'
Find rows that contain the word “apple”, but if the row also contains the word “macintosh”, rate it lower than if row does not. This is “softer” than a search for '+apple -macintosh', for which the presence of “macintosh” causes the row not to be returned at all.
'+apple +(>turnover <strudel)'
Find rows that contain the words “apple” and “turnover”, or “apple” and “strudel” (in any order), but rank “apple turnover” higher than “apple strudel”.
'apple*'
Find rows that contain words such as “apple”, “apples”, “applesauce”, or “applet”.
'"some words"'
Find rows that contain the exact phrase “some words” (for example, rows that contain “some words of wisdom” but not “some noise words”). Note that the “"” characters that enclose the phrase are operator characters that delimit the phrase. They are not the quotation marks that enclose the search string itself.
First rule:
grep "apple\|banana" filename
Other rules are causing problems.
Help me pls, sorry for bad english.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法使用 grep 进行评级,因此这些示例需要进一步的逻辑。其他示例可以使用
or
运算符以及 ?、* 和 + 限定符来解决。以下是您需要的正则表达式的几个示例:查找至少包含两个单词之一的行:
查找包含这两个单词的行:
查找包含单词“apple”但不包含“macintosh”的行:
查找包含以下单词的行:确切的短语“一些单词”
希望这有帮助
You can't do ratings with grep so those examples will require further logic. The other examples can be solved with
or
operator and the ?, *, and + qualifiers. Here a couple of examples of the regular expressions you need:Fnd rows that contain at least one of the two words:
Find rows that contain both words:
Find rows that contain the word “apple” but not “macintosh”:
Find rows that contain the exact phrase “some words”
Hope this helps