For last few days am learning this powerful utility in linux, though i confess that i did't pay much attention to it when it was in my syllabus.
But now I realised how powerful it can be to use. Though I havent perfectly masterd this utility but still keep on updating the thread as i find out more.
---------------------------------------------------------------------------
Everything is considered as stream in Linux. SED utilises the same concept to exploit it to make things easier for system administrators. I recommend to hav some basic knowledge of Regular Expressions before jumping in.
Syntax for this Utility
The noob Commands
1) Substitute Command
......................................................................................
a) single substitution
Syntax
s stands for substitute
old_value and new_value are self understood
/// these three forward slashes are required to enclose old_value and new_value, u can also use _ _ _ or : : : as long as the words dont contain them.
e.g.
echo string : just echoes the string entered
"|" its a pipe that connects previous command output to the input of next command, here the "string" is supplied as input to "sed" command.
Now try the same command to replace built by made using the above syntax,
Output:
This can be overcome easily. Read next point.
b) Global substitution
For all occurences to be updated u will hav to use "g" switch.
Syntax
. What about multiple word substituion ?
here we go
c) Multiple substitution
Syntax
or
e.g.
d) Fetching a real file.
Make a new file in home directory (or anywhere else but be sure to cd that directory in terminal).
Enter some lines
Like i created a file named "s" whose contents are;
..Replace "the" with "eht"
So what should we do ? Here comes regular expression to our help. Just remember that to replace a word take these word delimiter "\<" and "\>", anything written between them is taken to be a word.
For finding "the" we will have to use "\<the\>", as given below
e.g.

....................................................................................
But now I realised how powerful it can be to use. Though I havent perfectly masterd this utility but still keep on updating the thread as i find out more.
---------------------------------------------------------------------------
Everything is considered as stream in Linux. SED utilises the same concept to exploit it to make things easier for system administrators. I recommend to hav some basic knowledge of Regular Expressions before jumping in.
Syntax for this Utility
where things inside square brackets [] are optional.
The noob Commands
1) Substitute Command
......................................................................................
a) single substitution
Syntax
where
s stands for substitute
old_value and new_value are self understood
/// these three forward slashes are required to enclose old_value and new_value, u can also use _ _ _ or : : : as long as the words dont contain them.
e.g.
Output:
Explainanton:
echo string : just echoes the string entered
"|" its a pipe that connects previous command output to the input of next command, here the "string" is supplied as input to "sed" command.
Now try the same command to replace built by made using the above syntax,
guess what only first occurence will be replace and output will be
Output:
Actually sed work by reading line and processing the frst occurence in each line leaving all other untouched.
This can be overcome easily. Read next point.
b) Global substitution
For all occurences to be updated u will hav to use "g" switch.
Syntax
e.g.
Output:
Now its working fine
here we go
c) Multiple substitution
Syntax
or
-e means extension, it is an option to tell sed that there are more than one substituion.
e.g.
Output:
or
How about fetching a real file to do some job, uptil now i was using a string.
d) Fetching a real file.
Make a new file in home directory (or anywhere else but be sure to cd that directory in terminal).
Enter some lines
Like i created a file named "s" whose contents are;
Now we shall try out some substitution with further additon to ur knowledge.
..Replace "the" with "eht"
Output:
lol..the thing didnt work out as expected it replaced "the" in "then" at last line changin it to "ehtn"
So what should we do ? Here comes regular expression to our help. Just remember that to replace a word take these word delimiter "\<" and "\>", anything written between them is taken to be a word.
For finding "the" we will have to use "\<the\>", as given below
e.g.
Output:
Thats all for now, will keep it updating
....................................................................................