Edccccch Edccccch - 1 year ago 70
Linux Question

how to use array in sed shell command?

I am trying to do a list of name:

list = a, b, c, d, e
sed "/$list/d" output_file.txt

so that lines containing those variables a,b,c,d,e would be excluded from the output_file

Anyone please help

Answer Source

With GNU grep:

list=(a b c d e)
(IFS="|"; grep -vE "(${list[*]})" output_file)