我想搜索字符串
1 /value Error Code:12345/I
并将其替换为
1 /deleted by user/i
我怎样才能做到这一点sed
?
答案1
sed
可以使用变量分隔符:
$ echo "1 /value Error Code:12345/I " | sed 's;/value.*/I;/deleted by user/i;'
1 /deleted by user/i
/
但如果出于某种原因你必须使用,\
那么当它们是文字时你总是可以在它们前面添加:
$ echo "1 /value Error Code:12345/I " | sed 's/\/value.*\/I/\/deleted by user\/i/;'
1 /deleted by user/i
或者您可以sed
完全放弃并使用awk
, 作为/
输入字段和输出字段的分隔符:
$ echo "1 /value Error Code:12345/I " | awk -F'/' 'BEGIN{OFS=FS}{$2="deleted by user";$3="i";print}'
1 /deleted by user/i