ruby - Chaining sed statements -
i'm running dozen of sed
commands each capistranio deploy , wondering, if it's possible chain them 1 single sed
command, instead of firing dozens @ server.
task :taskname {:'foo' => foo, :'bar' => bar, :'foobar' => foobar, :'fubar' => fubar }.each |search, replace| run "sed -i 's/#{search}/#{replace}/' file.ext" end end
sed
natively accepts dozen of patterns (if reason prefer sed
):
{:foo => foo, :bar => bar, :foobar => foobar, :fubar => fubar}.inject("") |acc, k, v| acc += " -e 's/#{k}/#{v}'" end run "sed #{acc} file.ext"
Comments
Post a Comment