![](/img/trans.png)
[英]How to find multiple files, check for duplicates and replace with bash,sed script
[英]BASH Script - Find Replace multiple values
我有一个非常简单的bash脚本,正在将值传递给
我想从传递给脚本的值中删除前缀。
从传递的值中提取并test-
。
IN=$1
arrIN=(${IN//test-/})
echo $arrIN
所以test-12345返回12345
无论如何,有什么要修改的,以便删除test-
或local-
?
我试过了 :
arrIN=(${IN//test-|local-/})
但这没用..
谢谢
如果要将“ test-”或“ local-”更改为“”,则可以使用以下命令:
awk '{gsub(/test-|local-/, ""); print}'
您可以使用sed
并获得准确的结果
IN=$1
arrIN=$( echo $IN | sed 's/[^-]\+.//')
echo $arrIN
尝试如下使用sed:
IN=$1
arrIN=$(echo $IN | sed -r 's/test-|local-//g')
echo $arrIN
sed在这里将搜索“ test-”或“ local-”,并将其完全删除。
您可以在激活extglob
下执行此extglob
:
shopt -s extglob
arrIN=(${IN//+(test-|local-)/})
来自man bash :
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.