[英]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'
-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/ (
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.