Try the following script;
## $1 - Small File ## $2 - Large File sed 's/^/\//; s/$/\/d/; s/\\/\\\\/g' $1 > $HOME/sed_scpt.txt sed 's/\\/\\\\/g' $2 | sed -f $HOME/sed_scpt.txt > $HOME/desired_output.txt ## Alternatively, you could change the 2nd line with the following; sed -f $HOME/sed_scpt.txt $2 > $HOME/desired_output.txt Hope this helps.
NOTE: I've used GNU sed 4.2.1, if that matters as well.