shell脚本替换包含指定字符串的行

shell脚本替换包含指定字符串的行

啥也不是说了 直接上程序,

程序:
#!/bin/bash
#查找的字符串
str1=“string1”

#新字符串
newstr=“string2”

#被替换的文件名
filename=“wu.c”

#获取指定字符串的行号
line=sed -n "/$str1/=" $filename
#删除这行
sed -i “$line d” $filename

#在删除的行插入新字符串
sed -i “ l i n e i line i newstr” $filenam

猜你喜欢

转载自blog.csdn.net/huanting_123/article/details/84164676