【LeetCode】shell

195. Tenth Line

输出file.txt中的第十行

答案:

# Read from the file file.txt and output the tenth line to stdout.
#!/bin/bash
cat file.txt | sed -n '10p'

193. Valid Phone Numbers

找出file.txt中符合(xxx) xxx-xxxx or xxx-xxx-xxxx格式的电话号码

答案:

1 cat file.txt | grep  '^(\([0-9]{3}\) )[0-9]{3}-[0-9]{4}$|^([0-9]{3}-){2}[0-9]{4}$'

 

posted @ 2017-02-19 22:58  wilderness  阅读(181)  评论(0编辑  收藏  举报