Delete line contains pattern

Hi all,
I'm trying to delete line contains pattern from file using ex editor
I have tried something like this

 user@host ~ $/usr/bin/echo "/$pattern/d\nwq!"| /usr/bin/ex -s  file.txt

This line is from script
but it doesn't work
any idea

printf '/%s/d\nwq' "$pattern" | ex -s infile

If I recall correctly, some versions of ex require something like this:

printf '/%s/d\nw\nq' "$pattern" | ex -s infile

@radoulov
thanks , but both of them doesn't work any further idea

user@host ~ $ printf '/%s/d\nwq' "$pattern" | ex -s  file.txt
No previous regular expression
user@host ~ $ printf '/%s/d\nw\nq' "$pattern" | ex -s  file.txt
No previous regular expression

The code assumes the variable pattern is defined ...

pattern=<your_search_string>
printf '/%s/d\nwq' "$pattern" | ex -s  file.txt

@radoulov
Thanks it works