【发布时间】:2020-10-03 18:32:50
【问题描述】:
我有一个数组
arr=( 'error one' 'error two' 'error three' )
还有一个我想找出错误的文件
a.txt
带有内容(示例)。
error one
error two
error three
error four
error five
error six
error seven
eight
nine
ten
当我运行我的脚本时,我想忽略我已经找到的所有错误(数组中的错误)并找到新的错误。
到目前为止我有这个
arr=( 'error one' 'error two' 'error three' )
grep -v 'error one\|error two\|error three' a.txt | grep error
返回 this(正确)。
error four
error five
error six
error seven
不过,数组的内容会随着时间的推移而变化,这取决于我发现的更多错误,或者我停止发现的错误,我更愿意将数组作为一个整体来引用,而不是列出每个项目。
到目前为止,我有这样的东西。
arr=( 'error one' 'error two' 'error three' )
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
list=$(join_by "\|" "${arr[@]}")
echo ${list}
grep -v ${list} a.txt | grep error
这当然行不通,但我不知道如何从这里着手,或者是否要完全改变方法。
任何帮助将不胜感激。
【问题讨论】: