Grep Sed Lab - Tasks
Grep Sed Lab - Tasks
grep: ( grep,egrep,fgrep)
a) Write a grep command that selects the lines from the file1 that have exactly
three characters
b) Write a grep command that selects the lines from the file1 that have at least
three characters.
A: $ grep … filename
c) Write a grep command that selects the lines from the file1 that have three or
fewer characters
A: $ grep -v …. filename
d) Write a grep command that count the number blank lines in the file1
A: $ grep -c ^$ filename
e) Write a grep command that count the number nonblank lines in the file1
f) Write a grep command that selects the lines from the file1 that have the string
UNIX.
g) Write a grep command that selects the lines from the file1 that have only the
string UNIX.
h) Write a grep command that copy the file to the monitor, but delete the blank
lines.
A: $ grep -v ^$ filename
i) Write a grep command that selects the lines from the file1 that have at least
two digits without any other characters in between
sed: Tasks-solutions
a) Write a sed command that print numbers of lines beginning with “O”
b) Write a sed command that delete digits in the given input file.
c) Write a sed command that delete lines that contain both BEGIN and END
d) Write a sed command that delete lines that contain BEGIN but not END
e) Write a sed command that deletes the first character in each line in a file
f) Write a sed command that deletes the last character in each line in a file
g) Write a sed command to delete character before last character in each line in a file
h) Write a sed command that swaps the first and second character in each line in the file
i) Write a sed command that swaps the first and second word in each line in the file