从tcpdump输出中删除不必要的字符

时间:2018-06-07 12:36:34

标签: linux bash shell tcp tcpdump

我正在使用此命令监视本地(macOS)HTTP流量:

{"message":"body"}

POST /v2/8387efc52b0b6b14e83bcd1d1951bdb2 HTTP/1.1
Content-Type: application/json; charset=utf-8

我工作魔法,但也输出不必要的字符:

{{1}}

应该是:

{{1}}

1 个答案:

答案 0 :(得分:-1)

假设您显示的输入:

{"message":"body"}
14:29:07.725362 IP localhost.64258 > localhost.krb524: Flags [P.],seq 1004:1579, ack 469, win 11768, options [nop,nop,TS val 1448865401 ecr 1448865398], length 575 E..s..@.@..............\...^Z.>...-..h.....
V[.yV[.vPOST /v2/8387efc52b0b6b14e83bcd1d1951bdb2 HTTP/1.1
Content-Type: application/json; charset=utf-8

这行sed:

sed -e 's#^\(.*\)\(\(\(GET\|POST\|PUT\|DELETE\|OPTIONS\)\) /.*$\)#\2#g' input.txt | grep -E '({|Content-Type|GET|POST|PUT|DELETE|OPTIONS)'

将输出:

{"message":"body"}
POST /v2/8387efc52b0b6b14e83bcd1d1951bdb2 HTTP/1.1
Content-Type: application/json; charset=utf-8

这是你需要的吗?