Description
In this lab you will learn to write sed scripts
Please create a directory called ”rollno-lab9” where ”rollno” is your roll number. Keep all your scripts in this directory : script1.sh, script2.sed, script3.sed, script4.sed.
Use following command to create a tar ball :
tar -czvvf rollno-lab9.tgz rollno-lab9/
Upload this tarball ”rollno-lab9.tgz” on moodle.
Do not change cases, and do not deviate from the naming scheme for your scripts, directory or tar file to be uploaded. All the sed scripts will be run as sed -f script.sed inputfile.txt
- sh:
Write a sed command/script to emulate wc -l command. This file is run as a bash script by typing : . script1.sh filename.txt
- sed
Write a sed script which takes an input file and puts a line number at the beginning of each line.
This file is run as a bash script by typing : . script2.sh filename.txt For example :input.txt has the following contents:
this is first line
this is third line this is fourth line.
should be written to output.txt as follows: See that all blank lines also get a number.
(1) this is first line
(2)
(3) this is third line (4) this is fourth line
- sed:
Given input files contains new-lines and white spaces and tabs. Write a sed script to
- Remove all leading spaces
- Collapse every sequence of white spaces between two words in a singleline into a single space, and
- Collapse every sequence of white spaces between two lines into asingle newline. All other suffix and prefix whitespaces are to be deleted.
- Print the output to screen.For example
| ” | how | are you
fine. ” |
| becomes | ||
| ” | how are you fine.
” |
- sed :
There is a text file called input.txt such that there are four “strings” on each line.
For example:
VeenaDaniel Raj 3456
Veena Michael Raj3456
This has to be written so that all four fields in the record (line) are separated by a single tab. Therefore above output looks like
V eena Daniel Raj 4356
V eena Michael Raj 3465






