Sed '[address range | mode range]'s/old/new/[Replace tag] 'inputfile
The above sed replacement command syntax:
The address range or mode range is optional. If you do not specify it, sed will perform the replacement operation in the full text.
S: tells sed to perform the replacement operation.
Old: search for this string in inputfile. Regular Expressions can be used for the old position.
New: sed will use this string to replace old.
Replacing tags is optional and will be explained later in the next section.
Remember that the source file will not be modified; the replacement operation will only replace the values in the mode space, and then output to the standard output stdout ).
Below are two examples of sed replacement, which are marked in italic ).
Replace all managers with ctor:
$ Sed's/Manager/Director/'employee.txt
101, John Doe, CEO
102, Jason Smith, IT Director
103, RajReddy, Sysadmin
104, AnandRam, Developer
105, JaneMiller, SalesDirector
Use Director to replace managers that contain 'sales' rows:
$ Sed '/Sales/s/Manager/Director/'employee.txt
101, John Doe, CEO
102, Jason Smith, ITManager
103, RajReddy, Sysadmin
104, AnandRam, Developer
105, JaneMiller, Sales Director
Note that only one change in the address range is used in this example, instead of the two changes in the previous example.
This article is from the "old studio" blog, please be sure to keep this source http://lduan.blog.51cto.com/5428084/1303171