#定位到某一行 添加内容
lower_case_flag=`cat /etc/my.cnf|grep "^lower_case_table_names"`
if [ "X" == "X${lower_case_flag}" ]
then
line=`sed -n "/max_connections=/=" /etc/my.cnf |tail -n1`
echo "location [max_connections] line:${line}"
sudo sed -i "${line}s/.*/lower_case_table_names=1
&/" /etc/my.cnf
else
echo "lower_case_table_names=1 is exist,not need set."
fi
#替换
sed -i "s/pattern/modify/g" file
#替换整行
sed -i '/pattern/creplace' file
#删除匹配行 sed '/pattern/d' file 例:删除空包行 sed '/^$/d' file
$NF表示取最后一个域 # filename=/opt/file fileabs=$(echo $filename |awk -F/ '{print $NF}')