题目
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.
For example, assume that file.txt has the following content:
solution:
这里写代码片
sed -n -e ‘/(^[0-9]{3}-[0-9]{3}-[0-9]{4}∥[(][0−9]{3}[)][0−9]{3}−[0−9]{4})/p’ file.txt

本文介绍了一个使用Bash脚本的一行代码解决方案,用于从文本文件中读取并打印所有符合特定格式的有效电话号码。有效号码格式为:(xxx)xxx-xxxx 或 xxx-xxx-xxxx。

被折叠的 条评论
为什么被折叠?



