|
Softwares ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Main /
SedStreamEditorMain.SedStreamEditor HistoryHide minor edits - Show changes to output Changed lines 23-24 from:
to:
%blue%Sed editing commands Changed lines 10-11 from:
to:
%blue%p Print the current pattern space. Changed lines 34-35 from:
to:
%blue%Sed options Changed lines 50-51 from:
to:
%blue%suppress automatic printing of pattern space Changed lines 59-60 from:
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:
to:
%blue%Find and replace with sed Changed lines 102-103 from:
to:
%blue%To insert a string at the beginning of each line of a file, for instance for quoting: Changed lines 110-111 from:
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: Changed lines 12-21 from:
This You vi testfile vi is a powerfull editor. In 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:
to:
Sed options Option Effect Changed lines 87-95 from:
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 entire 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:
vi TesT file vi 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:
>> vi test file >> Insert 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:
vi test file 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:
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. 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. |