- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
假设我有一个包含以下内容的文件:
lmtp_bind_address (default: empty)
The LMTP-specific version of the smtp_bind_address configuration parameter. See there for details.
This feature is available in Postfix 2.3 and later.
lmtp_bind_address6 (default: empty)
The LMTP-specific version of the smtp_bind_address6 configuration parameter. See there for details.
This feature is available in Postfix 2.3 and later.
lmtp_body_checks (default: empty)
The LMTP-specific version of the smtp_body_checks configuration parameter. See there for details.
This feature is available in Postfix 2.5 and later.
我想获取以“lmtp_bind_address6”开头的行以及以下所有以空格开头的行:
lmtp_bind_address6 (default: empty)
The LMTP-specific version of the smtp_bind_address6 configuration parameter. See there for details.
This feature is available in Postfix 2.3 and later.
我如何在 bash 中执行此操作?
我正在离开 Centos 7 并在 Debian 8 上设置 Postfix。因此,我打算阅读 Postfix 版本 2.11.3 的 7255 行长的“man 5 postconf”。为了加快速度,我想在联机帮助页中对 Postfix 选项进行分组,这些选项涵盖相同的内容但适用于不同的协议(protocol),例如:
smtpd_tls_mandatory_ciphers
lmtp_tls_mandatory_ciphers
smtp_tls_mandatory_ciphers
tlsproxy_tls_mandatory_ciphers
正如您在上面看到的,这四个选项中的每一个都可以选择 TLS 密码,但适用于不同的协议(protocol)(SMTPD、LMTP 等)。
首先,我按以下方式对 Postfix 选项进行了分组:
postconf | awk -F"=" '{print $1}' | sed 's/ //g' | rev | sort | \
rev > postconf_options.txt
然后,我将联机帮助页转储到一个文件中:
man 5 postconf > postconf_manpage.txt
现在,我想遍历分组列表并将包含以下以空格开头的行的每个匹配项转储到第三个文件:
cat postconf_options.txt | while read I; do
grep -w "^$I" postconf_manpage.txt
done > postconf_manpage_grouped.txt
上面的 grep 命令只给出匹配的行,而不是后面以空格开头的行。
为了能够使用变量,我在 sed 中使用了双引号。这是来自 hek2mgl 的解决方案的完整过程:
postconf | awk -F"=" '{print $1}' | sed 's/ //g' | rev | sort | rev > postconf_options.txt
man 5 postconf > postconf_manpage.txt
cat postconf_options.txt | while read I; do sed -n "/^$I/{p;:a;n;/^[[:space:]]\|^$/{p;ba}}" postconf_manpage.txt; done > postconf_manpage_grouped.txt
最佳答案
我会使用 sed
:
sed -n '/^lmtp_bind_address6/{p;:a;n;/^[[:space:]]\|^$/{p;ba}}' file
/^lmtp_bind_address6/
匹配搜索模式{p;:a;n;/^[[:space:]]\|^$/{p;ba}}
确实使用 p
,定义了一个标签 :a
,它充当跳转标记,能够遍历以空格开头的行。 n
会将另一行读入模式缓冲区。 /^[[:space:]]\|^$/
匹配以空格或空行开头的行。如果是这种情况,该行将使用 p
打印,我们将使用 ba
跳回到 a
。关于bash - grep 与以下以空格开头的行匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38203009/
我有一个文件 test.log。非常大的日志文件。它有不同级别的日志记录。例如,trace , debug , info , warning和 error . 显然trace级别消息只是高速发送垃圾邮
我正在经历一些事情,发现了我无法理解的事情, grep -v grep 这意味着什么?我知道 -v 开关将选择所有不匹配的行。但为什么是第二个grep? 这是完整的命令: ps -ef | grep
我使用 egrep 输出一些带有平台名称的行: XXX | egrep "i686-nptl-linux-gnu$|i686-w64-mingw32$|x86_64-unknown-linux-gnu
grep退出状态部分报告中的手册: EXIT STATUS The exit status is 0 if selected lines are found, and 1 if not
我试图返回多个字符串的第一次出现,即,我想从以下文本中选择第一次出现 1259、3009 和 1589 的行。 ADWN 1259 11:00 B23 ADWN 3009
我猜它不是 Perl 兼容的正则表达式,因为有一种特殊的 grep具体来说就是 PCRE。什么是grep最相似? grep有什么特别的怪癖吗?我需要知道什么? (我习惯了 Perl 和 PHP 中的
有没有办法让 grep 从与搜索表达式匹配的文件中输出“单词”? 如果我想在多个文件中查找“th”的所有实例,我可以这样做: grep "th" * 但是输出会是这样的(粗体是我写的); some-t
我有许多(近 100 个)大 csv 文件,第一列中有 sellID。我知道某些 sellID 在 2 个或更多文件中重复 2 次或多次。是否可以使用 grep 找到所有重复的 sellID(创建映射
我有一个文件中的文件列表。该列表很大,并且文件名是非标准的:这意味着有些文件包含空格、非 ASCII 字符、引号、单引号... 因此,将庞大的文件列表作为参数传递给 grep 并不是一种选择: 因为我
我想在 shell 脚本中使用 grep 和两个变量 var = match cat list.txt | while read word_from_list; do grep "$word_
我有一个大文件,其中每一行都包含一个子字符串,例如 ABC123。如果我执行 grep ABC file.txt 或 grep ABC1 file.txt 我按预期返回这些行,但如果我执行 grep
当我执行以下 grep 时,我得到的结果我无法向自己解释: host:/usr/local/tomcat > grep '-XX:PermSize=256m' * RELEASE-NOTES:
这个问题在这里已经有了答案: grep recursively for a specific file type on Linux (5 个回答) 关闭4年前。 要在子目录中查找所有带有 .out 扩
有什么方法可以让我在搜索某些东西时使用 grep 忽略某些文件,相当于 svnignore 或 gitignore 的东西?我通常在搜索源代码时使用类似的东西。 grep -r something *
有没有办法让 grep 从匹配搜索表达式的文件中输出“单词”? 如果我想在多个文件中找到“th”的所有实例,我可以这样做: grep "th" * 但是输出会是这样的(粗体是我的); some-tex
我是 awk/sed 的完全菜鸟,所以如果我在这里遗漏了一些明显的东西,请原谅我。 基本上我正在尝试做一个嵌套的 grep,即类似于: grep $value `exim -Mvh $(`exim -
我正在尝试编写下载 node.js source 的脚本和 corresponding SHASUMS256.txt ,校验和,grep OK,不返回任何结果,使用 grep 的 -q 标志成功退出代
在 grep "str"* 这是否意味着 grep 执行 grep 的所有内容? 那么 grep -r "str". 的结果比前一个多 最佳答案 当您运行 grep str * 时,shell 将扩展
我正在尝试 grep 文件以查找匹配项的确切出现,但我也得到了更长的虚假匹配项: grep CAT1717O99 myfile.txt -F -w 输出: CAT1717O99 CAT1717O99
我有一个文件,其中包含我希望通过未指定分析运行的标识符(每行一个)。如果一切运行正常,分析将输出具有相同标识符的另一个列表(不一定按相同顺序)。 然而,事实证明,对某些输入标识符没有进行分析,并且这些
我是一名优秀的程序员,十分优秀!