Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

2321004

PRACTICAL :- 5

Aim:- To familiarize with the stream editor.


Theory:- The acronym SED stands for Stream Editor. It is a simple yet powerful
utility that parses the text and transforms it seamlessly. SED was developed during
1973–74 by Lee E. McMahon of Bell Labs. Today, it runs on all major operating
systems.
File to perform operations-

Addressing :- in sed addressing is done in two ways.


1.By line number
2.By Specifying a pattern which occurs in a line

 q command :-

 p command :-

 -n command :-

 $!p command :-
2321004

 -e in sed:-

Context addressing :-This addressing lets us to specify two or more patterns to


locate lines.The pattern must be bounded by a “/” on either sides of pattern.

Editing text :-Apart from selecting lines sed can also edit text itself like vi editor sed
use.

 Insert (i) Command :-Insert text before each line.

 Append(a) Command :-Insert text after each line.

 Change (c) Command :-Used to change content of a line.


2321004

 Delete(d) Command :-Used to delete the content of a line.


2321004

PRACTICAL :- 6
Aim:- To familiarize with the awk programming.
Theory:- Awk was developed in 1977. Awk is a scripting language used for
manipulating data and generating reports. The awk command programming
language requires no compiling and allows the user to use variables, numeric
functions, string functions, and logical operators.
Syntax :-$awk option ‘pattern{action}’filename
File to perform operations-

1. To print all the lines

2. To print all the fields

3. To print specific column

4. To print lines according to matched pattern


2321004

5. To print lines according to matched pattern in a specific column

6. To print the column if specific field satisfy the given condition

7. To print lines if specific column starts with character

8. To print lines if specific column ends with character

9. To print lines if satisfy all the conditions using &&(and operator)

10. To print lines if satisfy any one of the conditions using ||(or operator)

System variables
NR :-Number of records
2321004

NF :-Number of fields in a record

OFS :-Output field separater

ORS :-Output record separater


2321004

PRACTICAL :- 7
Aim:- Write a program in perl for scalar variables.
Theory:-A scalar is a single unit of data. That data might be an integer number,
floating point, a character, a string, a paragraph, or an entire web page. Simply saying
it could be anything, but only a single thing.

Program : -

Output : -
2321004

PRACTICAL:- 8
Aim:- Write a program in perl for array variables.
Theory:-A array is special type of variable .The array is used to store the list of value
and each object of list is termed as an element. Element can either be a number, string
or any type of scalar data.

Program : -

Output : -
2321004

PRACTICAL :- 9
Aim:- Write a program in perl for adding and removing elements from array.
Theory:-
1. push @ARRAY, LIST :-Pushes the values of the list onto the end of the array.
2. pop @ARRAY :-Pops off and returns the last value of the array.
3. shift @ARRAY :-Shifts the first value of the array off and returns it, shortening the array
by 1 and moving everything down.
4. unshift @ARRAY, LIST :-Prepends list to the front of the array, and returns the number
of elements in the new array.
Program : -

Output : -
2321004

PRACTICAL :- 10
Aim:- Write a program in perl for hashes variables.
Theory:-A hash is a set of key/value pairs. Hash variables are preceded by a percent
(%) sign. To refer to a single element of a hash, you will use the hash variable name
preceded by a "$" sign and followed by the "key" associated with the value in curly
brackets.

Program : -

Output : -

You might also like