有时我需要在所有手册页中查找某些单词。我知道apropos,但如果我理解它的手册正确,它会将搜索限制为仅描述。
每个手册页中都有一个简短的说明。apropos 搜索关键字实例的描述。
例如,如果我查找诸如“viminfo”之类的词,则根本找不到任何结果...
$ apropos viminfo
viminfo: nothing appropriate.
Run Code Online (Sandbox Code Playgroud)
...虽然这个词存在于 Vim 手册的后面部分(安装在我的系统上)。
Run Code Online (Sandbox Code Playgroud)-i {viminfo} When using the viminfo file is enabled, this option sets the filename to use, instead of the default "~/.vim? info". This can also be used to skip the use of the .viminfo file, by giving the name "NONE".
那么我怎样才能在每本手册的每个部分中查找一个词呢?
使用 awk,我可以打印给定索引的单词,如下所示。
$ echo "The quick brown fox jumps over the lazy dog" | awk '{print $3, $7}'
brown the
Run Code Online (Sandbox Code Playgroud)
但我也想获取指定单词“brown”和“the”之间的文本。所以我希望输出是这样的。
brown fox jumps over the
Run Code Online (Sandbox Code Playgroud)
没有必要专门使用 awk,但是单词的索引和标记化应该与 awk 的索引和标记化相匹配,以与我的 shell 脚本中使用 awk 的其他部分保持一致。
我想过将单词从第一个索引打印到最后一个索引,但这不会保留单词之间的空格。
用一种复杂但更准确的方式来说,我想获取从索引指定的某个单词的开头开始并在另一个索引指定的另一个单词的结尾结束的文本。我怎样才能做到这一点(最好没有 bash 循环)?