Re: bash command
On Thu, Oct 20, 2011 at 09:36:50AM +0100, Raf Czlonka wrote:
> On Thu, Oct 20, 2011 at 09:29:35AM BST, Jesus arteche wrote:
> > I want to create a script to change some words in some sonf files at the
> > start up of the system...do you know the command in bash for search the word
> > and replace it??
>
> You don't need bash for it, sed's your friend, e.g.:
>
> % sed -i 's/old_word/new_word/' /etc/conf.file
Proving that TIMTOWTDI (or, "You don't need sed for it, bash's your
friend):
while read line; do
echo ${line/old_word/new_word}
done < /etc/conf.file > /etc/conf.file.new
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.
By the way, I don't recommend this method. sed IS your friend, but bash
IS capable and that's what you asked for :)
--
Darac Marjal
Reply to: