linux - 来自 nl 和 tail 的行号之间的差异
问题描述
使用以下命令时:
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
所以,我可以看到它Step #6: Configure output plugins
在第 445 行。
我想输出第 445 行加上前五行(440-444 + 445),所以我使用:
tail -n+440 /etc/snort/snort.conf | head -n 6
但是,这给了我完全不同的结果。所以,我用行号对整个文件进行分类,调查并确实看到该行# Step #6: Configure output plugins
位于第 445 行...
在对 tail 命令进行多次试验和错误之后,我终于得到了预期的结果,但是我最初认为在 445 上的行实际上是在 529 上。我可以通过将先前的命令编号更改为来验证这一点:
tail -n+524 /etc/snort/snort.conf | head -n 6
然后我得到了最初预期的结果,显示了五行配置文件,# Step #6: Configure output plugins
作为输出的最后一行。
为什么感知的行号(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
推荐阅读
- mqtt - 导入 python 模块并访问 MQTT 端口
- java - Spring Boot JPA没有使用findById返回现有结果
- javascript - TypeError:this.state.map 不是函数
- sql - 数据库中属性的最佳数据类型是什么?整数还是字符?
- three.js - 三.js在场景左右移动相机
- c++ - 是什么导致这个有符号整数到无符号整数转换使用三元而不是短裤?
- r - 如何重塑数据框然后将其转换为 dgCMatrix?
- c++ - 冒号的意思
- elasticsearch-dsl - 如何使用 elasticsearch-dsl 以 json 格式保存文档
- database - YugabyteDB的2-DC异步复制机制是否支持一源多目标集群复制?