shell 之 使用sed替换文本中某个字符串
#!/bin/bash
if [ $# -lt 3 ]
then
echo "Usage:$0 <old_string> <new_string> <file path>"
exit 1
fi
old_string=$1
new_string=$2
file_path=$3
if [ -f "$file_path" ]
then
sed -i "s|$old_string|$new_string|g" $file_path
echo "string $old_string has been repalced with $new_string in file $file_path"
else
echo " File $file_path does not exist"
exit 1
fi
哪有什么胜利可言,坚持意味着一切。如想使用请备注转载链接~