1. Display all lines between 20 and 30 of
file x1.
$ Tail +25 x1 | tail -5
2. To display first 6 lines from file x1.
$ Head -6 x1
3. Display lines beginning either with
alphabet or digit from file x1.
$ grep "^[aeiou]*[0-9]" x1
4. Display lines that do not contain
"unix".
Grep “^[^unix]” filename
5. Display lines which are not starting
with 2 at beginning.
grep ‘^[^2]’ filename
6. Write a command to display all file
name containing only digits in filename.
ls | grep -e "^[0-9$]"
8. To display those lines in between 25
and 50 having pattern 'unix' in it.
sed -n 25,50p caroline | grep -n "unix"
9. Display lines before a line that
contain pattern 'xyz' in file f1.txt.
Grep ‘^xyz’ f1.txt
10. Find out the
number of the character '?' occur in file f1.txt.
Grep -c ‘?’ f1.txt
11. To count
the number of words in line 40 through 60 of file f1.txt.
sed -n 40,60p caroline |
wc -w
12. Display
lines having exactly 50 characters in file f1.
Sed -n 50p f1
13. count the number
of blank lines in file f1.
Grep -c “ “ f1
14. count the
number of blank lines in between 10 and 20 of x1.
grep -c "^$"
caroline
15. display
lines having at least one * character in file x1.
Grep ‘.’ X1
16. Display
the directory listing.
ls -d */
17. Display
files having read and write permission for the group.
Chmod 624 filename
18. Write a
command to substitute doshi with desai.
Sed -e
‘s/doshi/desai/g’ filname
19. To display
all lines that contain pattern bc* in a line.
grep “bc*” filname
20. To replace
tybca with TYBCA in input file in.sh and write those lines to output file
out.sh.
Sed -n ‘s/tybca/TYBCA/p’ in.sh>out.sh
21. To display
occurrences of 'BCA' in file x1.
Grep “BCA” x1
22. To replace
all occurrences of 'she' with 'he' and 'hi' with 'hello'.
sed -i ‘s/she/he/g’ filename | sed -i ‘s/hi/hello/g ’
filename
23. To print
lines with line nos. which contain "marketing".
grep -n ‘marketing’ file name
24. Display
lines which starts with 'The'.
Grep ‘^the’ filename
25. Delete all
vowels from file x1.
sed
's/[aeiou]//g' caroline
Post a Comment
If you have any doubts, Please let me know
Thanks!