File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ # #
2
+ # 193
3
+ # Valid Phone Numbers
4
+ # #
5
+ # Given a text file file.txt
6
+ # that contains a list of phone numbers (one per line),
7
+ # write a one-liner bash script to print all valid phone numbers.
8
+ #
9
+ # You may assume
10
+ # that a valid phone number must appear
11
+ # in one of the following two formats:
12
+ # (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)
13
+ #
14
+ # You may also assume each line in the text file
15
+ # must not contain leading or trailing white spaces.
16
+ #
17
+ # Example:
18
+ # Assume that file.txt has the following content:
19
+ # 987-123-4567
20
+ # 123 456 7890
21
+ # (123) 456-7890
22
+ #
23
+ # Your script should output the following valid phone numbers:
24
+ # 987-123-4567
25
+ # (123) 456-7890
26
+ # #
27
+ # https://leetcode.com/problems/valid-phone-numbers/
28
+ # #
29
+
30
+ #! /bin/bash
31
+
32
+ # Read from the file file.txt and output all valid phone numbers to stdout.
33
+ grep " \(^[0-9]\{3\}-[0-9]\{3\}-[0-9]\{4\}$\)\|\(^([0-9]\{3\}) [0-9]\{3\}-[0-9]\{4\}$\)" file.txt
You can’t perform that action at this time.
0 commit comments