Unix

Sed command in unix

sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream. While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the inputs, and is consequently more efficient.
The syntax for the sed  command is

The options are
-n: Suppress automatic printing of pattern space
-e: Add the script to the command to be executed
-f: Add the contents of the script file to the command to be executed
-i: Edit files in place
-r: Use extended regular expressions in the script
-s: Consider files as separate rather than a single continuous long stream
-u: Load minimum data from the input file and flush the output buffers more often

Examples of sed Command
Consider the following text
>cat file.txt
Unix is OS
sed is command in Unix
Unix and Linux are same family


  • Substitute String
>sed 's/sed/cat/ file.txt
Unix is OS
cat is command in Unix
Unix and Linux are same family

In the above command 's' denotes the substitution operation. Here "cat" replaces the "sed" string. '/' denotes the delimiters.





 



Powered by Blogger.