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
cat > file.txt <<EOF
987-123-4567
(123) 456-7890
0(001) 345-0000
(001) 123-345
linux grep命令
1.作用
Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expr
2.格式
grep [options]
3.主要参数
[options]主要参数:
-c:只输出匹配行的计数。
-I:不区分大 小写(只适用于单字符)。
-h:查询多文件时不显示文件名。
-l:查询多文件时只输出包含匹配字符的文件名。
-n:显示匹配行及 行号。
热门日志
分类
- Php(101)
- Java(8)
- Mysql(32)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(71)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Html(6)
- Windows(8)
- Message(12)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(11)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)
- about(1)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(30)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- Django(4)
- git(7)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(1)
- 架构(16)
- Vue(1)
最新日志
- Docker 那些事
- 欢迎您关注“刘善海价值分享”微信公众号!
- Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
- Linux vim/vi下backspace(退格键)出现^? 或^H
- python 如何通过subprocess.call调用自定义alias别名
- python2 python3中long类型的区别
- 10 个 Linux 中方便的 Bash 别名
- 'python' engine because the 'c' engine does not support regex separators
- importError c extension: No module named np_datetine not buit
- 四个提高工作效率的小技巧