Linux Shell Scripting Tutorial (LSST) v1.05r3 | ||
Chapter 7: awk Revisited | ||
|
Before getting started with tutorial you must know basic expression which is covered in our Learning expressions with ex tutorial. For this part of tutorial create demofile1. After creating the file type following sed command at shell prompt:
$ sed 's/Linux/UNIX(system v)/' demofile1
Hello World.
This is vivek from Poona.
I love linux.
.....
...
.....
linux is linux
Above sed command can be explained as follows:
Commands | Meaning |
sed | Start the sed command |
's/Linux/UNIX(system v)/' | Use substitute command to replace Linux with UNIX(system v). General syntax of substitute is s/pattern/pattern-to-substitute/' |
demofile1 | Read the data from demofile1 |
General Syntax of sed
Syntax:
sed -option 'general expression' [data-file]
sed -option sed-script-file [data-file]
Option can be:
Option | Meaning | Example |
-e | Read the different sed command from command line. | $ sed -e 'sed-commands' data-file-name $ sed -e 's/Linux/UNIX(system v)/' demofile1 |
-f | Read the sed command from sed script file. | $sed -f sed-script-file data-file-name $ sed -f chgdb.sed friends.tdb |
-n | Suppress the output of sed command. When -n is used you must use p command of print flag. | $ sed -n '/^\*..$/p' demofile2 |
awk miscellaneous | Redirecting the output of sed command |