Difference between revisions of "Sed"

From TBP Wiki
Jump to: navigation, search
Line 1: Line 1:
 
sed  is a stream editor.  A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).  While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient.  But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
 
sed  is a stream editor.  A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).  While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient.  But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.
 +
 +
=Using sed=
 +
 +
Sed can remove all instances of foo with bar with the following.
 +
    cat report.txt | sed 's/foo/bar/g' > report_new.txt
 +
 +
This removed all lines containing "loopback" from FILENAME and outputs into newfile.txt
 +
    sed '/loopback/d' ./FILENAME > newfile.txt
 +
 +
This will remove empty spaces from FILENAME.
 +
    cat FILENAME | sed '/^$/d;s/[[:blank:]]//g'

Revision as of 14:44, 16 April 2019

sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.

Using sed

Sed can remove all instances of foo with bar with the following.

   cat report.txt | sed 's/foo/bar/g' > report_new.txt

This removed all lines containing "loopback" from FILENAME and outputs into newfile.txt

   sed '/loopback/d' ./FILENAME > newfile.txt

This will remove empty spaces from FILENAME.

   cat FILENAME | sed '/^$/d;s/blank://g'