我想提取该部分
msg="services.facebook.com:Content Server, Rule_name:WAN6_Ongoing, SSI:N (Content)"
来自
src="192.168.1.1:443" dst="192.168.1.1:80" msg="services.facebook.com:Content Server, Rule_name:WAN6_Ongoing, SSI:N (Content)" note="WEB FORWARD" user="unknown" devID="ptz6e398b4a2" cat="Forward Web Sites"
当我输入
grep -Eo 'msg=".*"'
时,它会复制我
msg="services.facebook.com:Content Server, Rule_name:WAN6_Ongoing, SSI:N (Content)" note="WEB FORWARD" user="unknown" devID="ptz6e398b4a2" cat="Forward Web Sites"
我能够使用
grep -Eo 'src="[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}:[0-9]{1,10}"'
提取 src 和 dst 部分
我还想提取注释、用户和猫部分,将所有内容放入 csv 数据文件中。我没有用
awk
$ 来做,因为单词之间的空格每次都不一样。
使用
grep
$ grep -Eo '(msg|note|user|cat)="[^"]*"' input_file
msg="services.facebook.com:Content Server, Rule_name:WAN6_Ongoing, SSI:N (Content)"
note="WEB FORWARD"
user="unknown"
cat="Forward Web Sites"
$ grep -o 'msg="[^"]*"' file
msg="services.facebook.com:Content Server, Rule_name:WAN6_Ongoing, SSI:N (Content)"
$ grep -o 'src="[^"]*"' file
src="192.168.1.1:443"
$ grep -o 'dst="[^"]*"' file
dst="192.168.1.1:80"