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
posted @ 2023-03-30 16:15  by1314  阅读(166)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end