Leetcode no. 193
2016-07-29 16:13
120 查看
193. Valid Phone Numbers
Given a text file
one liner bash script to print all valid phone numbers.
You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)
You may also assume each line in the text file must not contain leading or trailing white spaces.
For example, assume that
Your script should output the following valid phone numbers:
# Read from the file file.txt and output all valid phone numbers to stdout.
awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
或者
sed -n -r '/^[0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
或者
grep -P '^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt
Given a text file
file.txtthat contains list of phone numbers (one per line), write a
one liner bash script to print all valid phone numbers.
You may assume that a valid phone number must appear in one of the following two formats: (xxx) xxx-xxxx or xxx-xxx-xxxx. (x means a digit)
You may also assume each line in the text file must not contain leading or trailing white spaces.
For example, assume that
file.txthas the following content:
987-123-4567 123 456 7890 (123) 456-7890
Your script should output the following valid phone numbers:
987-123-4567 (123) 456-7890
# Read from the file file.txt and output all valid phone numbers to stdout.
awk '/^([0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/' file.txt
或者
sed -n -r '/^[0-9]{3}-|\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$/p' file.txt
或者
grep -P '^(\d{3}-|\(\d{3}\) )\d{3}-\d{4}$' file.txt
相关文章推荐
- HDU 2845 Beans (最大不连续子序列和)(压缩求解)
- HDU 5773 The All-purpose Zero(贪心LIS)
- Android Studio 开发中的一个小功能 使用TextView搜索ListView
- si4438 cca 侦听
- grep、egrep、fgrep
- linux下的定时任务
- Android静态安全检测 -> 主机名弱校验
- 解决Apache CXF 不支持传递java.sql.Timestamp和java.util.HashMap类型问题
- 华为[编程题]最高分是多少
- JavaScript中null和undefined的比较和区别
- mysql定时器
- 命令模式
- [Web基础笔记]JavaScript部分
- Oracle 建立索引及SQL优化
- nginx菜鸟入门三
- 总结一下Android中主题(Theme)的正确玩法
- rabbitmq安装、集群搭建
- CentOS 与 RedHat 关系和区别
- Catch That Cow<poj3278>
- html 校验