我想在下面的例子中首先删除“/
”之后的数字。 (即22766
)
%ASA-4-106023: Deny udp src inside:10.252.0.175/22766 dst outside:192.5.5.241/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.175/53967 dst outside:198.41.0.4/53 by access-group
%ASA-4-106023: Deny tcp src inside:10.252.0.220/48971 dst outside:10.60.11.83/636 by access-group
%ASA-4-106023: Deny tcp src inside:10.252.0.220/33559 dst outside:10.60.11.84/636 by access-group
%ASA-4-106023: Deny tcp src inside:10.252.0.252/37021 dst outside:10.60.11.83/636 by access-group
%ASA-4-106023: Deny tcp src inside:10.252.0.252/44549 dst outside:10.60.11.84/636 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.179/48592 dst outside:202.12.27.33/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.179/23582 dst outside:202.12.27.33/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.175/27633 dst outside:192.5.5.241/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.175/22766 dst outside:192.5.5.241/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.175/13587 dst outside:192.5.5.241/53 by access-group
答案 0 :(得分:2)
使用以下sed
方法:
line="%ASA-4-106023: Deny udp src inside:10.252.0.175/22766 dst outside:192.5.5.241/53 by access-group"
$ echo "$line" | sed -E 's/\/[0-9]+/\//'
输出:
%ASA-4-106023: Deny udp src inside:10.252.0.175/ dst outside:192.5.5.241/53 by access-group
-E
选项允许扩展正则表达式(同样是-r
选项)
要获得更多" solid" (便携式)和简化解决方案,请使用以下内容:
sed 's~/[0-9]*~/~' testfile
~
作为sed
表达式
答案 1 :(得分:1)
@Bhavik:尝试:考虑你的Input_file应该与提供的一样。
awk -F"/" '{sub(/[0-9]+/,"",$2);print}' OFS="/" Input_file
将字段分隔符设置为“/”。所以只有sub(替换函数内置awk)才会改变输入文件的第二个字段中的所有数字。
答案 2 :(得分:0)
awk '{sub(/..... dst/," dst")}1' file
%ASA-4-106023: Deny udp src inside:10.252.0.175/ dst outside:192.5.5.241/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.175/ dst outside:198.41.0.4/53 by access-group
%ASA-4-106023: Deny tcp src inside:10.252.0.220/ dst outside:10.60.11.83/636 by access-group
%ASA-4-106023: Deny tcp src inside:10.252.0.220/ dst outside:10.60.11.84/636 by access-group
%ASA-4-106023: Deny tcp src inside:10.252.0.252/ dst outside:10.60.11.83/636 by access-group
%ASA-4-106023: Deny tcp src inside:10.252.0.252/ dst outside:10.60.11.84/636 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.179/ dst outside:202.12.27.33/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.179/ dst outside:202.12.27.33/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.175/ dst outside:192.5.5.241/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.175/ dst outside:192.5.5.241/53 by access-group
%ASA-4-106023: Deny udp src inside:10.252.0.175/ dst outside:192.5.5.241/53 by access-group