Display the lines from the file teknoscript.txt that do not contain the string lin.
grep -v lin teknoscript.txt
Find string 3
Display the lines from the file teknoscript.txt that contain the string “lin” along with its line numbers.
grep -n lin teknoscript.txt
Find string 5
Display the lines from the file teknoscript.txt that end with h.
grep 'h$' teknoscript.txt
Find string 7
Use the grep command to display all lines in teknoscript.txt that start with echo.
grep ^echo teknoscript.txt
Find string 8
Which command will display the lines in the file teknoscript.txt that are not comment lines( #)?
grep -v ^# teknoscript.txt
Grep Command – 2
Write a command to list all the lines from the file “employee.txt” which does not end with semicolon.
grep -v ';$' employee.txt
Grep Command – 3
Write a command to list all the lines from the file “employee.txt” ending with colon.
grep ':$' employee.txt
Tail Command – 2
Write a command to display the last 3 lines from the given file “sample.txt”.
tail -n 3 sample.txt
Redirect Command – 2
Write a command to redirect the number of lines of a file “input.txt” to the file “output.txt”.
wc -l "input.txt">"output.txt"
Write a command to count the total number of files and sub directories in the current directory.
ls -r | wc -l ./ -type -f -print | wc -l
What is the command to list all the files/directories having “s” as the first character from the current directory?
ls | grep '^s'
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.).
grep -i "Birbal" story.txt
Write a command to list all the files and directories in the current directory whose second character is a digit.
ls -d ./?[0-9]*
- All programs of Introduction to Unix
- All programs of File System
- All Programs of Filters
- All Programs of Bourne Shell