[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash command



On Fri, Oct 21, 2011 at 03:42:36PM -0400, Stefan Monnier wrote:
> > Sadly, this can't be done in-place, so you'll either need to use mv to
> > replace /etc/conf.file with /etc/conf.file.new or repeat the loop (with
> > no substitution) to copy /etc/conf.file.new into /etc/conf.file.
> 
> It can be done "inplace" with `rm' in place or `mv':
> 
>     (rm /etc/conf.file;
>      while read line; do
>          echo ${line/old_word/new_word}
>      done >/etc/conf.file) </etc/conf.file

True, but that's using external tools. My point was that it's difficult
to do simply with bash (which is what the OP asked for). If you're
allowing the use of external tools, sed is much easier.


-- 
Darac Marjal


Reply to: