将文本文件中的tcpdump输出写入一行 [英] Write tcpdump output in a text file into a single line
问题描述
我想将文本输出中的所有行连接成一行. 使用以下命令,我可以监视DHCP流量:
I want to concatenate all lines in text output into one line. With the following command I can monitor DHCP traffic:
tcpdump -lni eth0 -vvv -s 1500 '((udp port 67) and (udp[247:4] = 0x63350103))' | grep --line-buffered -E -i 'client-id|requested-ip|hostname'
对于每个新连接,我都会在新行中看到3个结果(IP,MAC,主机名).
For every new connection I see 3 results ( IP, MAC, Hostname ) every one of them on a new line.
是否可以将每个结果都写入这三个结果,但只能写入一行并写在文件上?
That's possible to write this three every results but into only one line and write on a file?
推荐答案
使用tr
删除带有-d的换行符.在我的机器上运行并使用en0而不是eth0,我在一行上看到了这一点:
Use tr
to remove newlines with -d. Running on my machine and using en0 instead of eth0, I see this on one line:
$ tcpdump -lni en0 -vvv -s 1500 '((udp port 67) and (udp[247:4] = 0x63350103))' | grep --line-buffered -E -i 'client-id|requested-ip|hostname' | tr -d '\n' > output.txt
$ cat output.txt
Client-ID Option 61, length 7: ether 6c:96:cf:d8:7f:e7 Requested-IP Option 50, length 4: 172.31.99.198 Hostname Option 12, length 3: "mbp"
>
将覆盖具有stdin内容的文件.
查看tr的联机帮助页.
>
Will overwrite a file with contents of stdin.
Check out tr's manpage.
这篇关于将文本文件中的tcpdump输出写入一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!