bash 编写 cat 和 echo 脚本

bash scripting cat and echo

我是 bash 脚本的新手,我对此有错误:

    tab=( "^[A-Z]\{4,\}[0-9]\{4,\}" )

    for (( i=0; i<=$(( ${#tab[*]} - 1 )); i++ ))    
    do      
       tmp+=" grep -v \"${tab[i]}\" |"  
    done    
    # for remove the last |     
    chaine=`echo $tmp| rev | cut -c2- | rev`    
    #result anticipe "cat ${oldConfFile[0]} | grep -v "^[A-Z]\{4,\}[0-9]\{4,\}"
    cat ${oldConfFile[0]} | echo $chaine    

我的问题是,如何同时使用cat和echo?

非常感谢。

您不需要为每个模式都进行 grep,只需使用管道 (|) 连接您的模式并 grep 一次。例如,如果要从 file 中过滤掉包含 foobarbaz 的行,请使用以下内容:

grep -v 'foo|bar|baz' file

您可以像这样在调用之外构建模式以获得更好的可读性:

my_pattern='foo'
my_pattern+='|bar'
my_pattern+='|baz'

grep -v "$my_pattern" file