193 Valid Phone Numbers
Given a text file file.txt that 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.
Example:
Assume that file.txt has 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 在文本中找出(xxx) xxx-xxxx or xxx-xxx-xxxx 这样的字符串
grep -e '^[0-9]\{3\}-[0-9]\{3\}-[0-9]\{4\}$' -e '^([0-9]\{3\}) [0-9]\{3\}-[0-9]\{4\}$' file.txt
193 Valid Phone Numbers的更多相关文章
- LeetCode(193. Valid Phone Numbers)(sed用法)
193. Valid Phone Numbers Given a text file file.txt that contains list of phone numbers (one per lin ...
- LeetCode 193. Valid Phone Numbers
分析 难度 易 来源 https://leetcode.com/problems/valid-phone-numbers/ 题目 Given a text file file.txt that con ...
- [LeetCode] Valid Phone Numbers 验证电话号码
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- Valid Phone Numbers
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [Bash]LeetCode193. 有效电话号码 | Valid Phone Numbers
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- [LeetCode] 193. Valid Phone Numbers_Easy tag: Bash
Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bas ...
- LeetCode All in One 题目讲解汇总(持续更新中...)
终于将LeetCode的免费题刷完了,真是漫长的第一遍啊,估计很多题都忘的差不多了,这次开个题目汇总贴,并附上每道题目的解题连接,方便之后查阅吧~ 477 Total Hamming Distance ...
- LeetCode Shell Problems
195. Tenth Line -- 第十行 How would you print just the 10th line of a file? Solution: awk 'NR==10' file ...
- 【LeetCode】shell
195. Tenth Line 输出file.txt中的第十行 答案: # Read from the file file.txt and output the tenth line to stdou ...
随机推荐
- spring MVC 统一异常处理(webapi和web分开处理)
转载: http://blog.csdn.net/m13321169565/article/details/7641978 http://blog.csdn.net/ethan_fu/article/ ...
- 【BZOJ1306】[CQOI2009]循环赛(搜索)
[BZOJ1306][CQOI2009]循环赛(搜索) 题面 BZOJ 洛谷 题解 爆搜一下,\(hash\)记录是否已经考虑过这个状态,记忆化解决问题. #include<iostream&g ...
- 【BZOJ1078】[SCOI2008]斜堆(性质题)
[BZOJ1078][SCOI2008]斜堆(性质题) 题面 BZOJ 洛谷 题解 考虑一下这道题目的性质吧.思考一下最后插入进来的数是什么样子的.首先因为它是最后插入进来的,所以一定是比某个数小,然 ...
- Sql Server数据库小知识点总结
把我在开发时候遇到的一点小知识持续更新在这里~ 1.where条件时常变 where UserID='1' 这里的UserID呢,它的值是经常在变化的,有时候要查2,有时候要查3的,有时候要查全部人! ...
- vs2015的visual assist X options安装过程
1.安装VA_X之前,请先关闭VS2015程序. 2.下载VA_X_Setup2048.exe和VAX2048破解补丁.zip. 3.双击运行VA_X_Setup2048.exe文件,安装完成后出现 ...
- webGL和three.js的关系
如今浏览器的功能越来越强大,而且这些功能可能通过JavaScript直接调用.你可以用HTML5标签轻松地添加音频和视频,而且可以在HTML5画布上创建各种交互组件.现在这个功能集合里又有了一个新成员 ...
- UVA 12307 Smallest Enclosing Rectangle
https://vjudge.net/problem/UVA-12307 求覆盖所有点的最小矩形面积.周长 相当于求凸包的最小面积外接矩形.最小周长外接矩形 结论: 这个矩形一定有一条边和凸包上一条边 ...
- PHP中GET和POST区别
1. get是从服务器上获取数据,post是向服务器传送数据.2. get是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到.post是通过H ...
- Flex 编写 loading 组件
Flex 界面初始化有时那个标准的进度条无法显示,界面长时间会处理空白的状态!我们来自定义一个进度条, 这个进度条加载在 Application 应用程序界面的 <s:Application 标 ...
- VIM 配置随手记
刚开始使用VIM, 主要想用它来写python. 目标是颜色比较舒适, 并且能够自动换行自动补全. .vimrc 设置 这是类似 .bashrc 的配置文件, vim 的各种配置都可以在里面实现. 一 ...