FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Join us as Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
 

Linux Programming Tutorial: Using SED to Edit strings in a File in Linux

jawahar
8/18/2005 2:03:41 AM, Views: 1395
string editor, sed, is used for editing lines in a file or a stream;
output is going to the standard output and can be re-directed to a
new file.

syntax: sed [options] 'command1' [files]
            sed [options] -e 'command1' [-e command2 ...] [files]
            sed [options] -f script [files]

delete lines from 3 through 5 in file list.txt:
sed '3,5d' list.txt

delete lines that contain "o" at the beginning of the line:

sed '/^o/d' list.txt

translate capital c,r,o into small c,r,o:
sed 'y/cro/cro/' list.txt

delete ampty lines:
sed '/^$/d' list.txt

replace string oop with wee for the first occurence on a line

sed 's/oop/wee/' lsst.txt

remove ss string (replace with empty entry)for the first
occurence on a line:

sed 's/ss//' list.txt

remove ss string for all occurences on a line:
sed 's/ss//g' list.txt

substitute a single space for any number of spaces wherever
they occur on the line:

sed 's/ */ /g' list.txt

substitute underscore for any number of spaces wherever they
occur on the line:

sed 's/ */_/g' list.txt
Next Steps:
Add this Tutorial to:
Blink Blink del.icio.ous Del.icio.us Digg Digg
Fark Fark Furl Furl Google Google
Reddit Reddit Simpy Simpy Spurl Spurl
Technorati Technorati Windows Live Win Live Yahoo Yahoo
Rate Me!
Not Yet Rated!
Rate:
Send Private MessageSend Message
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
        (Link Rules) 
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
Options
Linux Programming RSS Feed
Most Popular Tutorial
Most Popular Solution
No Records!
Top Rated
No Records!
Top Rankers
Overall
1. jawahar (50)
Yearly -2008
No Rankings!
Expertsforge Sponsors
bnrtop