You are on page 1of 15

S.

YESWANTH

18H61A05A5

Write a shell script that deletes all lines


containing the specified word in one or more
files supplied as arguments to it.

Write a shell script that display a date in


following format. Fri 22 June 2021
Command-date +”%a %d %b %Y”

a) How does the command mv bar1 bar2


behave, where both bar1 and bar2 are
directories, when (i) bar2 exists and (ii)
bar2 doesn’t exist?
(ii)

when the dir do not exists it will first create and then move all the
contents and files present in the directory bar1 to bar2 but it will
remove the bar1 directory as we are moving.

(i)
When the directory exist then we will just move all files from bar1
to bar2 and delete the bar1.

How will you display only the lines common


to two files?

We use comm command will be used in here.


The command cmp foo1 foo2 displays
nothing. What does it indicates?
They two are identical.

b) Create the emp.dat using vi editor with


following fields emp_ID, emp_name,
designation, Salary, Location. Stored at least
10 records in it. Use the “:” (colon) as a field
separator. Practice the following :
 Insert/edit mode operations
This can be done using Insert command in
linux ie press “i” in the keyboard to keep it in
the insert or edit mode.
 All the basic command mode basic
operation like copy, paste, delete, undo,
redo, etc.
Copy-To copy first we copy a content and
then paste it in the command line.

Paste-To paste something in the command


line we use Ctrl+v to paste.
Delete-This can be done using the keyword
“dd” in the command line this will delete the
whole line.
“dw” will delete only that particular number.
Undo-This can be done by press “u” keyword
in the command line.

Redo-This can be done by press “Ctrl+r”


keyword in the command line.
 All the basic advanced command mode
operation to save data, show line number,
copy, paste, delete, create new file,
encryption, etc.
save-This can be done by first clicking Esc and
then :wq in the lower bottom.
show line number-To show line number we
first go to normal mode and then type “:set
number” to the command line.
create file-To create a file in vi we use vi
filename.

encryption-This can be done by entering into


normal mode by Esc and then “:X”.Then you
will be told to give key and then type that
key again.

c) Practice the grep, egrep and fgrep with


all the options and observe the output of
below commands:
 $time egrep "[Ll]inu." file.txt 
egrep- uses extended regular expressions slowest
 $time grep "[Ll]inu." file.txt 
grep-basic regular expressions

 $time fgrep "[Ll]inu." file.txt 


Fgrep-no regular expressions fastest

You might also like