bash command

Paul Graydon paul at paulgraydon.co.uk
Thu Oct 20 08:58:49 UTC 2011


On 10/19/2011 10:29 PM, Jesus arteche wrote:
> Hey guys,
>
> 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??
>
> Thanks
>
>
You're looking for 'sed'.  It's very powerful and exceptionally useful.  
In it's roughest form you can do straight text substitution:

sed -i.bkp 's/foo/bar/g'  file.name

That will replace all instances of foo with bar wherever they occur in 
the file, and leave you with a filename.bkp backup copy of the unaltered 
config (-i = in-place edit)

You can read about sed here: http://tldp.org/LDP/abs/html/x22860.html
If you're going to be spending time using Linux, I would strongly 
recommend taking the time to learn sed, and specifically how to form 
'Regular Expressions' (used text pattern matching).  It may take a bit 
of effort to get your head around it initially but the rewards are 
significant in what it then allows you to do. 
http://www.regular-expressions.info/

Paul
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-server/attachments/20111019/f0c94ac9/attachment.html>


More information about the ubuntu-server mailing list