Find string2
Question:
Display the lines from the file teknoscript.txt that do not contain the string lin.
Code:
findstring2.sh
grep -v lin teknoscript.txt
Find string 3
Question:
Display the lines from the file teknoscript.txt that contain the string “lin” along with its line numbers.
Code:
findstring3.sh
grep -n lin teknoscript.txt
Find string 5
Question:
Display the lines from the file teknoscript.txt that end with h.
Code:
findstring5.sh
grep 'h$' teknoscript.txt
Find string 7
Question:
Use the grep command to display all lines in teknoscript.txt that start with echo.
Code:
findstring7.sh
grep ^echo teknoscript.txt
Find string 8
Question:
Which command will display the lines in the file teknoscript.txt that are not comment lines( #)?
Code:
findstring8.sh
grep -v ^# teknoscript.txt
Grep Command – 2
Question:
Write a command to list all the lines from the file “employee.txt” which does not end with semicolon.
Code:
cmd5.sh
grep -v ';$' employee.txt
Grep Command – 3
Question:
Write a command to list all the lines from the file “employee.txt” ending with colon.
Code:
cmd9.sh
grep ':$' employee.txt
Tail Command – 2
Question:
Write a command to display the last 3 lines from the given file “sample.txt”.
Code:
cmd6.sh
tail -n 3 sample.txt
Redirect Command – 2
Question:
Write a command to redirect the number of lines of a file “input.txt” to the file “output.txt”.
Code:
cmd10.sh
wc -l "input.txt">"output.txt"
Count Files
Question:
Write a command to count the total number of files and sub directories in the current directory.
Code:
cmd7.sh
ls -r | wc -l ./ -type -f -print | wc -l
List Files
Question:
What is the command to list all the files/directories having “s” as the first character from the current directory?
Code:
cmd11.sh
ls | grep '^s'
Word Search
Question:
Write a command to display all the lines which contains the word “Birbal” from a file “story.txt”. The search should not be case sensitive( “Birbal”, “BirBal”, “BIRBAL” etc.).
Code:
cmd8.sh
grep -i "Birbal" story.txt
Pattern Search
Question:
Write a command to list all the files and directories in the current directory whose second character is a digit.
Code:
cmd12.sh
ls -d ./?[0-9]*
Recommended:
- All programs of Introduction to Unix
- All programs of File System
- All Programs of Filters
- All Programs of Bourne Shell