sed -i

来源:互联网 发布:淘宝大学讲师 魔布 编辑:程序博客网 时间:2024/05/16 04:18

sed -i

在含有特定字符串的行前插入新行

sed -i '/特定字符串/i 新行字符串'

/*

sed删除和替换:

sed -i '/^DROP/d' tourdb.sql
sed -i 's/tourdb/dcdb/g' tourdb.sql

*/

 

例:
#! /bin/sh
#version=1315991028
#cur=`date +%s`
#run=$(expr $cur \- $version)
#values=3600
#echo $run
#if [ $run -lt 3600 ]
#then
count=`/bin/cat /etc/firewall.sh |/bin/grep "iptables -A INPUT -s 192.168.2.0/24 -p icmp -m state --state NEW -j ACCEPT" |wc -l`
echo $count
if [ $count -lt 1 ]
then
sed -i '/iptables -A INPUT -s 192.168.1.1 -p icmp -m state --state NEW -j ACCEPT/ iiptables -A INPUT -s 192.168.2.0/24 -p icmp -m state --state NEW -j ACCEPT' /etc/firewall.sh
fi
#fi
count=`/sbin/iptables -L |/bin/grep "ACCEPT     icmp --  192.168.2.0/24        anywhere            state NEW" |wc -l`
echo $count
if [ $count -lt 1 ]
then
/sbin/iptables -I INPUT 5 -s 19.2.172.0/24 -p icmp -m state --state NEW -j ACCEPT
fi

原创粉丝点击