Starting from:

$25

CS213-Lab 9 Solved

CS-213 : Lab 9 : sed

1.    script1.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

2.    script2.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

 

3.    script3.sed:

Given input files contains new-lines and white spaces and tabs. Write a sed script to

(a)    Remove all leading spaces

(b)    Collapse every sequence of white spaces between two words in a singleline into a single space, and

(c)    Collapse every sequence of white spaces between two lines into asingle newline.    All other suffix and prefix whitespaces are to be deleted.

(d)   Print the output to screen.For example


how
       are             you

fine.


 
 
becomes
 

how are you fine.


4.    script4.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

 

More products