From 6d3c97617cb64e060ac1571a19546d2938b17277 Mon Sep 17 00:00:00 2001 From: Aaron Sutter <1gst3r@gmail.com> Date: Sun, 5 Nov 2017 17:28:24 -0800 Subject: [PATCH 1/2] script matches on valid phone numbers, leetcode accepted --- easy/Shell/file.txt | 3 +++ easy/Shell/valid_phone_numbers.sh | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 easy/Shell/file.txt create mode 100755 easy/Shell/valid_phone_numbers.sh diff --git a/easy/Shell/file.txt b/easy/Shell/file.txt new file mode 100644 index 0000000..ab5499c --- /dev/null +++ b/easy/Shell/file.txt @@ -0,0 +1,3 @@ +987-123-4567 +123 456 7890 +(123) 456-7890 diff --git a/easy/Shell/valid_phone_numbers.sh b/easy/Shell/valid_phone_numbers.sh new file mode 100755 index 0000000..2725646 --- /dev/null +++ b/easy/Shell/valid_phone_numbers.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +while read -r line ; do [[ $line =~ ^[0-9]{3}-[0-9]{3}-[0-9]{4}$ ]] && echo $line; [[ $line =~ \([0-9]{3}\)[[:space:]][0-9]{3}-[0-9]{4}$ ]] && echo $line;done < file.txt From 3afa872775a114352cd795bf6c0395d6becba607 Mon Sep 17 00:00:00 2001 From: Aaron Sutter <1gst3r@gmail.com> Date: Sun, 5 Nov 2017 17:31:14 -0800 Subject: [PATCH 2/2] forgot recent changes. adding now --- easy/Shell/file.txt | 8 ++++++++ easy/Shell/valid_phone_numbers.sh | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/easy/Shell/file.txt b/easy/Shell/file.txt index ab5499c..501311d 100644 --- a/easy/Shell/file.txt +++ b/easy/Shell/file.txt @@ -1,3 +1,11 @@ 987-123-4567 123 456 7890 (123) 456-7890 +987-123-45674 +(123) 456-78904 +9871-123-4567 +(1231) 456-7890 +987-1232-45674 +(123) 4563-7890 +(123) 456-7890 +0(001) 345-0000 diff --git a/easy/Shell/valid_phone_numbers.sh b/easy/Shell/valid_phone_numbers.sh index 2725646..7297187 100755 --- a/easy/Shell/valid_phone_numbers.sh +++ b/easy/Shell/valid_phone_numbers.sh @@ -1,3 +1,3 @@ #!/bin/bash -while read -r line ; do [[ $line =~ ^[0-9]{3}-[0-9]{3}-[0-9]{4}$ ]] && echo $line; [[ $line =~ \([0-9]{3}\)[[:space:]][0-9]{3}-[0-9]{4}$ ]] && echo $line;done < file.txt +while read -r line ; do [[ $line =~ ^[0-9]{3}-[0-9]{3}-[0-9]{4}$ ]] && echo $line; [[ $line =~ ^\([0-9]{3}\)[[:space:]][0-9]{3}-[0-9]{4}$ ]] && echo $line;done < file.txt