gpt4 book ai didi

linux - nl 和 tail 的行号之间的差异

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

当使用以下命令时:

nl /etc/snort/snort.conf | grep output

我得到以下输出:

 33  #  6) Configure output plugins
445 # Step #6: Configure output plugins
450 # output unified2: filename snort.log, limit 128, mpls_event_types, vlan_event_types

所以,我可以看到步骤#6:配置输出插件位于第 445 行。

我想输出第445行加上前五行(440-444 + 445),所以我使用:

tail -n+440 /etc/snort/snort.conf | head -n 6

但是,这给了我完全不同的结果。因此,我用行号对整个文件进行了分类,进行了调查,确实发现 # Step #6: 配置输出插件 行位于第 445 行...

经过对 tail 命令的多次尝试和错误,我终于得到了预期的结果,但是我最初认为在 445 上的行实际上是在 529 上。我可以通过将之前的命令编号更改为来验证这一点:

tail -n+524 /etc/snort/snort.conf | head -n 6

然后,我得到了最初预期的结果,显示了配置文件的五行,其中 # Step #6: 配置输出插件 作为输出的最后一行。

为什么感知的行数之间存在差异(445 与 529)?

最佳答案

看一下 nl 的原始输出。它不对空行进行编号。

$ nl /etc/snort/snort.conf
...
32 ###################################################
33 # Step #1: Set the network variables. For more information, see README.variables
34 ###################################################

35 # Setup the network addresses you are protecting
36 ipvar HOME_NET any

37 # Set up the external network addresses. Leave as "any" in most situations
38 ipvar EXTERNAL_NET any

39 # List of DNS servers on your network
40 ipvar DNS_SERVERS $HOME_NET

41 # List of SMTP servers on your network
42 ipvar SMTP_SERVERS $HOME_NET

43 # List of web servers on your network
44 ipvar HTTP_SERVERS $HOME_NET
...

使用-ba对所有行进行编号。默认值为 -bt:仅包含数字非空行。

nl -ba /etc/snort/snort.conf | grep output

关于linux - nl 和 tail 的行号之间的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57914122/

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