gpt4 book ai didi

linux - 使用 'grep' 和 'man' 以及一些选项输出文本

转载 作者:太空宇宙 更新时间:2023-11-04 05:51:46 26 4
gpt4 key购买 nike

我需要输出man中描述的命令grep的所有选项(只是像-z这样的键,没有重复和描述)。我尝试这样做:grep -o "-z"|man grep但它并没有像我预期的那样工作。所以我的问题是:如何在没有任何描述和重复的情况下获取命令 grep 的所有 key 选项。

最佳答案

这是我的问题的答案:

man grep | grep -o '\-\w\b'

首先,我们使用 man grep 命令,然后使用正则表达式 grep -o '\-\w\b' 将输出传输到 grep 命令。

-o option - shows only the part of a matching line that matches PATTERN

- \w option - matches any single "word" character, namely alphanumeric or underscore. This is equivalent to [a-zA-Z0-9_]. Conversely, capital \W means "any non-word character".

- \b option - means "word boundary", which is like an anchor because it doesn't consume any characters.

关于linux - 使用 'grep' 和 'man' 以及一些选项输出文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32906547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com