In: Computer Science
linux: Regular expressions
file name: studentsyslog.txt
Use a regular expression and grep or egrep to filter the file so the output displays only the items requested. Put your full command in the space provided
1.Show only the lines that end with an ellipses (3 dots) :
grep '\.\.\.$' studentsyslog.txt
Grep is aLinux / Unix command-line tool used to search for a string of characters in a specified file
grep
uses regexes; .
means "any
character". So we need to escape the dots in order to find dots in
the file. We have used three dots in the command so we escape then
by backword slash like this '\.\.\.'
In regular expressions, we use $ to match a word/words at the end of a line.
Here we use this to mach the dots.
Like this: '\.\.\.$' which will match 3 dots at the end of each line.
The syntax for code is:
grep regularexpression filename
Here is the command with output:
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.