Recent Changes - Search:

Softwares

.

SedStreamEditor

Main.SedStreamEditor History

Hide minor edits - Show changes to output

March 23, 2006, at 12:42 PM by 210.18.59.46 -
Changed lines 23-24 from:
Sed editing commands
to:
%blue%Sed editing commands
March 23, 2006, at 12:40 PM by 210.18.59.46 -
Changed lines 10-11 from:
to:
%blue%p Print the current pattern space.
Changed lines 34-35 from:
Sed options
to:
%blue%Sed options
Changed lines 50-51 from:
suppress automatic printing of pattern space
to:
%blue%suppress automatic printing of pattern space
Changed lines 59-60 from:
See the lines not containing the search string, using the example below.
to:
%blue%See the lines not containing the search string, using the example below.
Changed lines 68-69 from:
To print the file starting from a certain line until the end of the file, use a command similar to this
to:
%blue%To print the file starting from a certain line until the end of the file, use a command similar to this
Changed lines 75-77 from:
Find and replace with sed
to:
%blue%Find and replace with sed
Changed lines 102-103 from:
To insert a string at the beginning of each line of a file, for instance for quoting:
to:
%blue%To insert a string at the beginning of each line of a file, for instance for quoting:
Changed lines 110-111 from:
Insert some string at the end of each line:
to:
%blue%Insert some string at the end of each line:
Changed lines 119-120 from:
Multiple find and replace commands are separated with individual -e options:
to:
%blue%Multiple find and replace commands are separated with individual -e options:
March 23, 2006, at 12:35 PM by 210.18.59.46 -
Changed lines 12-21 from:
This is a test file.
This
is a test file.
You can create a test file using a vi editor
You
can create a test file using a vi editor
vi testfile
vi testfile
vi is a powerfull editor.

In
the above example the lines containing the search string are printed twice.
to:
This is a test file.
This is a test file.
You
can create a test file using a vi editor
You can create a test file using a vi editor
vi testfile
vi testfile
vi is a powerfull editor.

In the above example the lines containing the search string are printed twice.
Changed lines 33-34 from:
Sed options
Option Effect
to:
Sed options
Option Effect
Changed lines 87-95 from:
This is a Test file.
You can create a Test file using a vi editor
vi Test file
vi is a powerfull editor.

First occurrence of the search string has been replaced, if there are more that one string to be replaced.
Then we have
to use the the example below. Use the g command to indicate to sed that it should examine the
entire
line instead of stopping at the first occurrence of your string:
to:
This is a Test file.
You can create a Test file using a vi editor
vi Test file
vi is a powerfull editor.

First occurrence of the search string has been replaced, if there are more that one string
to be replaced.Then we have to use the the example below. Use the g command to indicate to sed that it should examine the entire line instead of stopping at the first occurrence of your string:
Changed lines 95-100 from:
This is a TesT file.
You can create a TesT file using a vi editor
vi TesT file
vi
is a powerfull editor.
to:
This is a TesT file.
You can create a TesT file using a vi editor
vi TesT file
vi is a powerfull editor.
Changed lines 103-109 from:
>> This is a test file.
>> You can create a test file using a vi editor
>> vi test file
>>
vi is a powerfull editor.

Insert
some string at the end of each line:
to:
>> This is a test file.
>> You can create a test file using a vi editor
>> vi test file
>> vi is a powerfull editor.

Insert some string at the end of each line:
Changed lines 111-116 from:
This is a test file.(end of line)
You can create a test file using a vi editor(end of line)
vi test file
(end of line)
vi is a powerfull editor.(end of line)
to:
This is a test file.(end of line)
You can create a test file using a vi editor(end of line)
vi test file(end of line)
vi is a powerfull editor.(end of line)
Changed lines 120-123 from:
You cAn creAte A TEST file using A vi editor
vi TEST file

vi is A powerfull editor.
to:
You cAn creAte A TEST file using A vi editor
vi TEST file
vi is A powerfull editor.
March 23, 2006, at 12:33 PM by 210.18.59.46 -
Added lines 1-126:
%blue%Sed stream editor


$ cat -n sedexample
1 This is a test file.
2 You can create a test file using a vi editor
3 vi testfile
4 vi is a powerfull editor.


$ sed '/test/p' sedexample
This is a test file.
This is a test file.
You can create a test file using a vi editor
You can create a test file using a vi editor
vi testfile
vi testfile
vi is a powerfull editor.

In the above example the lines containing the search string are printed twice.

Sed editing commands
Command Result
a\ Append text below current line.
c\ Change text in the current line with new text.
d Delete text.
i\ Insert text above current line.
p Print text.
r Read a file.
s Search and replace text.
w Write to a file.

Sed options
Option Effect
-e SCRIPT Add the commands in SCRIPT to the set of commands to be run while processing the input.
-f Add the commands contained in the file SCRIPT-FILE to the set of commands to be run while processing the input.
-n Silent mode.
-V Print version information and exit.


$ sed -n '/test/p' sedexample
This is a test file.
You can create a test file using a vi editor
vi testfile

-n, --quiet, --silent

suppress automatic printing of pattern space

$ cat -n sedexample
1 This is a test file.
2 You can create a test file using a vi editor
3 vi test file
4 vi is a powerfull editor.


See the lines not containing the search string, using the example below.

$ sed '/test/d' sedexample
vi is a powerfull editor.

$ sed '1,3d' sedexample
vi is a powerfull editor.


To print the file starting from a certain line until the end of the file, use a command similar to this

$ sed '3,$d' sedexample
This is a test file.
You can create a test file using a vi editor



Find and replace with sed

s/regexp/replacement/
Attempt to match regexp against the pattern space. If success-
ful, replace that portion matched with replacement.

$ cat -n sedexample
1 This is a test file.
2 You can create a test file using a vi editor
3 vi test file
4 vi is a powerfull editor.

$ sed 's/test/Test/' sedexample
This is a Test file.
You can create a Test file using a vi editor
vi Test file
vi is a powerfull editor.

First occurrence of the search string has been replaced, if there are more that one string to be replaced.
Then we have to use the the example below. Use the g command to indicate to sed that it should examine the
entire line instead of stopping at the first occurrence of your string:

$ sed 's/test/TesT/g' sedexample
This is a TesT file.
You can create a TesT file using a vi editor
vi TesT file
vi is a powerfull editor.


To insert a string at the beginning of each line of a file, for instance for quoting:
$ sed 's/^/>> /' sedexample
>> This is a test file.
>> You can create a test file using a vi editor
>> vi test file
>> vi is a powerfull editor.

Insert some string at the end of each line:

$ sed 's/$/(end of line)/' sedexample
This is a test file.(end of line)
You can create a test file using a vi editor(end of line)
vi test file(end of line)
vi is a powerfull editor.(end of line)


Multiple find and replace commands are separated with individual -e options:

sed -e 's/test/TEST/g' -e 's/a/A/g' sedexample This is A TEST file.
You cAn creAte A TEST file using A vi editor
vi TEST file
vi is A powerfull editor.

By default sed prints its results to the standard output, most likely your terminal window.
Edit - History - Print - Recent Changes - Search
Page last modified on March 23, 2006, at 12:42 PM