-2

I new in bash scripting and i bug with this:

    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    

My trouble is there, how use cat and echo at the same time ?

thanks a lot.

1 Answers1

1

You don't need to grep for each pattern, just join your patterns with pipes (|) and grep once. For example, if you want to filter out lines that contain foo, bar and baz from file, use the following:

grep -v 'foo|bar|baz' file

And you can build up the pattern outside of the invocation for better readability like this:

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

grep -v "$my_pattern" file
oguz ismail
  • 1
  • 16
  • 47
  • 69