[英]Bash variable search and replace instead of sed
I need to parse out instances of +word+
line by line (replace +word+
with blank). 我需要逐行解析+word+
实例(用空白替换+word+
)。 I'm currently using the following (working) sed regex: 我目前正在使用以下(有效的)sed正则表达式:
newLine=$(echo "$line" | sed "s/+[a-Z]\++//g")
This violates "SC2001" according to "ShellCheck" validation; 根据“ ShellCheck”验证,这违反了“ SC2001”;
SC2001: See if you can use ${variable//search/replace} instead.
I've attempted several variations without success (The string "+word+" remains in the output): 我尝试了几种变体而没有成功(字符串“ + word +”保留在输出中):
newLine=$(line//+[a-Z]+/)
newLine=$(line/+[a-Z]+//)
newLine=$(line/+[a-Z]\++/)
newLine=${line//+[a-Z]+/}
and more..
I've heard that in some cases sed is necessary, but I would like to use Bash's built in find and replace if possible. 我听说在某些情况下sed是必要的,但我想尽可能使用Bash内置的find和replace方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.