how can sed get patterns from a file
You may want the -i option to xargs (check the man page for details). That essentially replaces {}
with the pattern, and runs the command once per pattern. So, it'll run sed on the file once per pattern; you'll need to bear that in mind when creating your patterns.
user@host [/tmp]$ cat patterns
a
[pd]ie
user@host [/tmp]$ cat file
hat
cherry pie
die alone
eat cake
user@host [/tmp]$ cat patterns | xargs -i sed 's/{}/moo/' file
hmoot
cherry pie
die moolone
emoot cake
hat
cherry moo
moo alone
eat cake
Alternatively, you could use something else to dynamically build the sed script from your patterns file. For example, you could use sed on your pattern file to apply them all in one pass over the file. :)
user@host [/tmp]$ sed 's|^|s/|;s|$|/moo/;|' patterns | tee patterns.sed
s/a/moo/;
s/[pd]ie/moo/;
user@host [/tmp]$ sed -f patterns.sed file
hmoot
cherry moo
moo moolone
emoot cake
You can build a regex like this:
regex=$(tr '\n' '|' < patterns.txt)
sed -ri "s/$regex/replacement/" filename
You may choose to add the "g" flag to the s/// command.