Text Size
   
Home Technology | complicates our life Linux Stuffs Find and Replace in Linux Command Line
Sep 06
Monday

 

 

          edzofcit.com

 

What's Hot

Tudlo

Tudlo is the easy way to find and review about events, places and establishment.  Everybody knows that asking someone is the best way to find places and establishments. Tudlo collects and organize these recommendations in one convenient site -- and that is Tudlo.com.

Playing

Playing

  • Tribal Wars
  • Call of Duty 4
  • NFS Most Wanted
  • CNC Generals
  • Kanes Wrath
.

Watching

Watching

  • Smallville
  • Heroes
  • Terminator(Sarah Chronicles)
  • Chuck
  • Dexterk
.

Doing

Doing

  • IP Telephony
  • Open Source Technology
  • Web Development
  • Asterisk
.
Find and Replace in Linux Command Line PDF  | Print |  E-mail
User Rating: / 1
PoorBest 
Written by Administrator   
Wednesday, 28 January 2009 05:46

If doing find and replace words in Windows is as easy as opening the file in a text editor and clicking ctrl+F or F5 button, In Linux, you can easily do it through its command line using SED command.

 

For example we have a file which looks like this.

 #cat edzofcit.txt
Hi, my name is Eddie. Eddie is my name. Edzofcit is my website. Eddie is my first name

The filename is edzofcit.txt and we want to change Eddie into Joseph. To change Eddie into Joseph, you can write these command below.

# sed -i -e "s/Eddie/Joseph/" edzofcit.txt



So if we show the edzofcit.txt file, it will now look like this.


#cat edzofcit.txt
Hi, my name is Joseph. Joseph is my name. Edzofcit is my website. Joseph is my first name

 Since the command has "/"  in it, you need specify an escape character "\\" before "/". Take a look below for example.

 # sed -i -e "s/Eddie/Joseph\\/Eddie/" edzofcit.txt

 We changed Eddie into Joseph/Eddie.

 #cat edzofcit.txt
Hi, my name is Joseph/Eddie. Joseph/Eddie is my name. Edzofcit is my website. Joseph/Eddie is my first name

 

That's all. With that code, you can now make a  powerfule script that can replace files all at once..

See you at the next tutorial. :)

Last Updated ( Tuesday, 14 July 2009 06:09 )
 
Comments (1)
Help
1 Wednesday, 28 January 2009 07:16
Administrator
Hope this tutorial can help many people. Thanks..

Add your comment

Your name:
Subject:
Comment:
Home Technology | complicates our life Linux Stuffs Find and Replace in Linux Command Line