nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

what is the use of sed command

This is a discussion on what is the use of sed command within the Shell scripting forums, part of the Development/Scripting category; hi, what is the use of sed command and i had seen one command like sed ' s/ \([0-9]\)/,\1/ s/\([0-9]\) ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 07-25-2006, 02:17 PM
Junior Member
 
Join Date: Jul 2006
Posts: 3
Rep Power: 0
selvam
Default what is the use of sed command

hi,

what is the use of sed command and i had seen one command like

sed '
s/ \([0-9]\)/,\1/
s/\([0-9]\) /\1,/
' test | sort -k1,3

here i am getting bit confusion with frontslash and backslah why they but / and \ again and again. plz explain to me . i am new learner to shell script
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2006, 12:27 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

sed is for editing file without using text editor such as vi.
sed '/foo/s//bar/g' data.txt
above command is nothing but find and replace operation according to given regex. it will find word occurrence of word foo and replace with bar from data.txt file. \ use to disable special regex character. In this case it will disable ( and ), which is use to match entire word/regex. special escapes \1 refer to the corresponding matching sub expressions from first regex.

If you have sample input file just paste it so that I can explain it better.
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 12-06-2007, 10:18 PM
Junior Member
User
 
Join Date: Dec 2007
My distro: Ubuntu - Gutsy Gibbon
Posts: 1
Rep Power: 0
jarhed is on a distinguished road
Smile The use of sed...

I just just wanted to share a perfect example of using the sed command...

I am a multimedia and web-designer and often have to change multiple items throughout websites. Long story short, one of my clients needed their e-mail address's changed throughout their ENTIRE site. The site is fairly large, with roughly 50 pages or so (greenhouse with a page for all varieties of plant.

By using the sed command, I was able to search the ENTIRE site and replace the old e-mail address's with the new one. If I were to have to opened each .html file in nano I would have shot myself...This turned a lengthy job into a 2 min project.

FYI.
If you are planning on using any of the illegal characters in the sed command, make sure to use the '\' prior to the character itself.

ie. #: sed 's/info@youroldaddress\.com/info@yournewservice\.st\.com/g' .html

Hope this sheds some light on ONE of it's MANY, MANY uses...and hopefully if your in the same situation, helps you out!

Enjoy,
Jimmi
jarhed
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +5.5. The time now is 08:45 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36