INTRODUCTION
SED : stands for stream editor used for Filtering and Transforming on input stream from Files or pipelines
HOW TO INSTALL SED :
- Debian
sudo apt-get install -y sed
- RedHat | CentOS
yum install sed -y
HOW TO USE SED WITH EXAMPLES
- You can use it to print lines from text file
sed '3,1p' head.txt
HINT :
Here will print the content of text file with the highlighted line number 3 only
You can also print range of lines for example from line 1 to 3
sed '1,3p' head.txt
- You Can also print selected lines only without all lines exist on text file by using argument -n
sed -n '1,3p' head.txt
- You can also print lines with specific streams or start with specific stream
sed -n '/unixcop/p' head.txt
sed -n '/Mostafa/p' head.txt
sed -n '/^Bye/p' head.txt
- You Can Use it to replace some stream with another stream
sed 's/Mostafa/UNIXCOP/' head.txt
- You can also append some streams to the lines
sed 's/unixcop/ & Mostafa and Omar and Ahmed/' head.txt
- You can use it to delete range of lines or streams
sed '3,4d' head.txt
sed '/^Bye/d' head.txt
- You can use sed to read sed command from text file with .sed extension
HINT :
You must write the sed command with the following form shown in command.sed file
I used to delete the line that starts with Bye word
sed -f command.sed head.txt
CONCLUSION
This article clarify the usages of sed editor with examples .. For more info about sed use the following ” man sed ”