LeetCode关于shell的几个问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode关于shell的几个问题相关的知识,希望对你有一定的参考价值。

195. Tenth Line

输出file.txt中的第十行

答案:

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

193. Valid Phone Numbers

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

答案:

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

 

以上是关于LeetCode关于shell的几个问题的主要内容,如果未能解决你的问题,请参考以下文章