Valid Phone Numbers
franklinqin0 Shell
# Solution
# Using egrep
egrep grep -E.
The difference is that -E option enables usage of extended regexp patterns. It will allow you using of such meta-symbols as +, ? or |. They aren't ordinary characters like we used to have in words or filenames but control commands for grep binary itself. Thus, | means logical OR.
egrep '^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$' file.txt
1
# Using awk
awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
1
# Using sed
sed -r -n '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
1