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
With GNU grep:
list=(a b c d e)
(IFS="|"; grep -vE "(${list[*]})" file)
or with GNU sed:
list=(a b c d e)
(IFS="|"; sed -E "/(${list[*]})/d" file)
list=(a b c d e); (IFS="|"; grep -vE "(${list[*]})" input_file > output_file)You can use a BASH array to generate a regex with pipe (alternation):
list=(a b c d e) # original array
printf -v re "%s|" "${list[@]}" # genera a regex delimited by |
sed -E "/${re%|}/d" file # use sed on this regex
sed use: sed -E -i.bak "/${re%|}/d" file