In: Computer Science
Linux regular expressions:
file name: lab3test.txt
Create regular expressions that meet the following criteria. You may use grep or egrep to answer these questions.
1.Match any lines that contain a phone number with the format 222-222-2222.
Here is the linux command that matches the given criteria. It not only matchs "222-222-2222" format, but also matches
(222)222-2222
222 222 2222
2222222222
Please let me know if you need any
modifications.
Command:
grep '[0-9]\{3\}[ -]\?[0-9]\{3\}[ -]\?[0-9]\{4\}' phonenumbers
Grep is a Linux / Unix command-line tool used to search for a string of characters in a specified file. The text search pattern is called a regular expression.
Where phonenumbers is the name of the file where numbers exists.
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.