问题
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'
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?
回答1:
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"
>
Will overwrite a file with contents of stdin.
Check out tr's manpage.
来源:https://stackoverflow.com/questions/59224563/write-tcpdump-output-in-a-text-file-into-a-single-line