Write commands to do the following.
a) Find the Present working Directory
b) Find the users currently logged in
c) View the contents of any file
d) rename a file
e) change the password of any user
f) Delete a directory
g) Display the current time
h) create a user
i) View only top 5 lines of a file
j) create a new directory
Explain the following commands
Printf
who
whereis
file
grep
33. Write shell scripts for the following (Do not use sed and awk)
Take two numbers as input from user, find which is greater
Count the number of times the word “the” appears in a given file.
List all the lines that begin with a number
Count the number of blank lines
Search for all numbers in a file and sort them.
34. Write scripts for the following (Do not use sed and awk)
Print only the current day, not the date
List all the words that have the letter “e” in it.
List all the users that exist in your system
Count the number of directories to be changed to reach the “pwd”
Add line numbers to a file.
35. Write scripts that will do the following (Do not use sed and awk)
Give execute permission to all the files in a directory
Work like the command “ls”.
Take a number as input from user and generate the table for the same
List all the words that have letter “t” or “r” in it.
Count only the number of files in a directory.
36. Write scripts that will do the following (do not use sed and awk)
Read a username from the user and create a user by that name.
Read a username from the user and check if the user is logged in or not.
Take a string and a filename as input from user and search for the same in the
given file
Take input on command line and echo them in the script, also echo the number of arguments passed.
Take integers as input on the command line and find the average of the numbers in the script.
37. Write Scripts/commands to do the following,
Run a process in the background.
Count the number of processes running currently
List only the Pids of the currently running processes.
Check if a certain process is running currently or not.
Terminate a certain process
38. A) Write a script that will display the following menu
Issue a book
Return a book
Delete a book. (6)
Each of the above options should have a sub menu that asks for the name of the book and then echo the action that is done.
38. B) Write a script that will take two numbers from the user and generate the table for the
first number till the limit mentioned by the second number. (4)
39. a) Write a sed script that will delete all the lines in a file that have the letter “the” in it.
The file by itself need not be modified, only the output should be modified.
b) Write a sed script that will print all that will count the number of blank lines in a file.
c) Write a sed script that will remove the first word of every line
d) Write a sed script to print the line numbers of every line that has the word “the” in it.
e) Consider a file that has the following contents.
1
2
11
22
111
222
Write a sed script that will modify it to
2
1
22
11
222
111
40. Write a sed script that will take two strings and a file name as input from the user.
Let the inputs be string1,string2, and filename. The script should do the following.
To append the string2 at every place string1 is present in the file “test”
To insert the string2 at every place string1 is present in the file “test”
Delete all the lines in the file “test” that have the string test
Print the all the line numbers in which string1 is present in the file “test”.
Replace the whole line that has the string1 with only stirng2.
41. Write a sed script that will take two strings and a file name as input from the user.
Let the inputs be string1,string2, and filename.
Delete the line next to the one that has string1 in “test”
Print only the lines next to ones that have string1 in file “test”
Print both the lines, one having the string1 and the one next to it
Delete both the lines, one having the string1 and the one next to it.
Delete only the line next to the one that has the string “test”,
42. Write sed scripts for the following .
Take a string as an input from the user and surround the string by brackets at all the locations is appears in the input file
Replace all the numbers in the input file by the letter NUM.
Replace all the capital “D” with small “d”.
Replace the first letter in every line by a blank.
Delete all the blank lines in the file.
43. Write sed scripts that will do the following.
Delete blank lines only if there are 2 continuous blank lines.
Delete a line having the string” good” only if the line following it is blank.
That will work like the command “cat”
That will delete every line that starts with a T.
That will show all the special characters in a file.
44. Write awk scripts that will do the following.
Print only the first column of a file
Print second column of every line that has the string “the”
Print the line numbers in which the string “the” appears
Print the number of columns in each line
Print “hello world” with out taking any file as input.
45. Write awk scripts that will do the following
Print the last field of every line
That works like the command “cat”
That will print first column of ever line, out put being separated by “**”.
That will not output the blank lines in a file
That will output all the lines other than the second line.
46. Describe the following system variables used in AWK, also give examples of the same.
NF
NR
FILENAME
ORS
OFS
47. A) Write an awk script that will print out the following information about an input file
a) The number of words in the file
b) The number of lines in the file.
c) The number of capital letters in the file
d) The number of numbers in the file. (4)
47. B) Write an awk script that will take a number N as input on the command line. Then count the number of lines in the input file that have fields greater than N and display the complete lines. In place of the lines that do not have the required number of fields print the difference between the number of fields that are present and N. (6)
48. A)Write an awk script that will take two files as input and find the file that have more number of words in it. (7)
48 B) Explain the difference between the following pair of commands related to sed
a)n,N b) p,P c)d,D (3)
49 A) Write an awk script that will take two files as input and find the file that has more occurrences of the word “the”. (7)
49 B) Explain the difference between the following pair of system variables related to awk
a)NF,NR b) OFS,ORS c) FILENAME,FNR (3)
50 A) Write an awk script that will take two files as input and find the file that have more number of lines in it. (5)
50 B) Write an awk script that will take two files as input from the user and print out the differences between them. Compare only the corresponding fields. (5)
51. A) Store your important phone numbers in a hash. Write a program to look up numbers by the person's name. (5)
51. B) Write your own program to capture all the prime numbers between 2 and a number the user gives you. (5)
52. A) Write a program that reads a list of strings on separate lines and prints out the list in reverse order. (4)
52. B) Write a program that reads a string and a number and then prints the string the number of times indicated by the number on separate lines. (4)
52 C) Write a program that prompts for and reads two numbers, and then prints out the result of the two numbers multiplied together. (2)
53. Write and explain the code for the following with regard to perl: (5+5)
a) Determining the number of elements in an array
b) How to grab a slice of an array
54. A) Write a program to check whether a number is a palindrome or not. (5+5)
54. B) Write a program to implement the bubble sort on a set of numbers.
55. Write and explain the code for the following with regard to perl: (5+5)
a) Using the Parameter Array (@_)
b) Passing Parameters by Reference