简体   繁体   English

用空格(“”)代替点(。)awk,sed或grep

[英]substituting a dot (.) with a space (“ ”) awk, sed or grep

I need to go through tcpdump files which have IP addresses followed by their source or destination port in this way: 192.168.1.0.80 to this one: 192.168.1.0 80 . 我需要通过tcpdump文件,这些文件具有IP地址,后跟源或目标端口: 192.168.1.0.80到这一个: 192.168.1.0 80

How can I do this using awk, sed or grep? 我怎么能用awk,sed或grep做到这一点?

With sed : sed

tcpdump -v -n |
sed -r 's@([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\.([0-9]{1,5})@\1 \2@g'

EXPLANATION 说明

  • -r switch stands for extented regex (I use it to avoid parentheses backslash) -r开关代表扩展的正则表达式 (我使用它来避免括号反斜杠)
  • s@@@ is a substitution skeleton , the delimiter can be anything we want, not only s/// . s@@@是替换骨架 ,分隔符可以是我们想要的任何东西,而不仅仅是s/// s/before/after/ S /前/后/
  • ( group and capture to \\1 (to \\N) (分组并捕​​获到\\ 1(到\\ N)
  • [0-9]{1,3} any character of: '0' to '9' (between 1 and 3 times (matching the most amount possible)) [0-9]{1,3}任何字符:'0'到'9'(1到3次之间(匹配尽可能多的数量))
  • \\. a literal '.' 文字“。”
  • ) end of a capture )结束捕获
  • \\1 and \\2 are the captured stuff \\1\\2是捕获的东西
  • g modifier stands for all occurences g修饰符代表所有出现的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM