In: Computer Science
PLEASE USE LINUX/UNIX
1.Use either pico, vi, or cat to create the following file and name it as “mysedfile”:
Name Class1 Class2 Class3
Tom 92 94 88
Nancy 91 85 95
Lisa 99 77 96
Jerry 84 98 90
2. Please use sed command(s) to complete the following tasks.
All the question were executed on Linux Unbuntu.
Let me know if you have any doubts or need any modifications.
mysedfile is in desktop.
mysedfile
display Tom’s record.
sed -n '/Tom/p' mysedfile
SED command in UNIX is stands for stream editor and it can perform lot’s of function on file like, searching, find and replace, insertion or deletion.
The -n option asks sed to not display the regex or patten unless explicitly asked to do so. Try removing -n option and you will understand the difference:
display Lisa’s record.
sed -n '/Lisa/p' mysedfile
display both Tom’s and Lisa’s records.
sed -n '/Tom/p' mysedfile && sed -n '/Tom/p' mysedfile
I used && (or operator) to print both the lines
remove the blank line(s) from “mysedfile.”
sed -r '/^\s*$/d' mysedfile
replace all the digits with *.
sed 's/[0-9]/*/g' mysedfile
[0-9]
will match all digits, and replace every
single one with *
If you have any doubts, leave a comment below before rating. I'll be happy to assist you further.
Do UPVOTE this as I have put a lot of EFFORT in answering this question. It really helps me.