Linux Shell Scripting Tutorial (LSST) v1.05r3
Prev
Chapter 7: awk Revisited
Next

Redirecting the output of sed command

You can redirect the output of sed command to file as follows
$ sed 's/Linux/UNIX(system v)/' demofile1 > file.out
And can see the output using cat command as follows
$ cat file.out

Deleting blank lines

Using sed you can delete all blank line from file as follow
$ sed '/^$/d' demofile1
As you know pattern /^$/, match blank line and d, command deletes the blank line.

Following sed command takes input from who command and sed is used to check whether particular user is logged or not.
$ who | sed -n '/vivek/p'
Here -n option to sed command, suppress the output of sed command; and /vivek/ is the pattern that we are looking for, finally if the pattern found its printed using p command of sed.


Prev
Home
Next
sed - Quick Introduction
Up
How to write sed scripts?