Nav: << previous: 192.统计词频 | next: 194.转置文件 >>


Description

tab: English
 
<p>Given a text file <code>file.txt</code> that contains a list of phone numbers (one per line), write a one-liner bash script to print all valid phone numbers.</p>
 
<p>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)</p>
 
<p>You may also assume each line in the text file must not contain leading or trailing white spaces.</p>
 
<p><strong class="example">Example:</strong></p>
 
<p>Assume that <code>file.txt</code> has the following content:</p>
 
<pre>
987-123-4567
123 456 7890
(123) 456-7890
</pre>
 
<p>Your script should output the following valid phone numbers:</p>
 
<pre>
987-123-4567
(123) 456-7890
</pre>
 
 
 
---
 
[submissions](https://leetcode.com/problems/valid-phone-numbers/submissions/) | [solutions](https://leetcode.com/problems/valid-phone-numbers/solutions/)
 
 
tab: 中文
 
<p>给定一个包含电话号码列表(一行一个电话号码)的文本文件 <code>file.txt</code>,写一个单行 bash 脚本输出所有有效的电话号码。</p>
 
<p>你可以假设一个有效的电话号码必须满足以下两种格式: (xxx) xxx-xxxx 或 xxx-xxx-xxxx。(x 表示一个数字)</p>
 
<p>你也可以假设每行前后没有多余的空格字符。</p>
 
<p> </p>
 
<p><strong>示例:</strong></p>
 
<p>假设 <code>file.txt</code> 内容如下:</p>
 
<pre>
987-123-4567
123 456 7890
(123) 456-7890
</pre>
 
<p>你的脚本应当输出下列有效的电话号码:</p>
 
<pre>
987-123-4567
(123) 456-7890
</pre>
 
 
 
---
 
[提交记录](https://leetcode.cn/problems/valid-phone-numbers/submissions/) | [题解](https://leetcode.cn/problems/valid-phone-numbers/solution/)
 
 

Solutions & Notes

properties:
  note.updated:
    displayName: Last Updated
  note.relative_links:
    displayName: Related Links
  note.desc:
    displayName: Description
  note.grade:
    displayName: Rating
  note.program_language:
    displayName: Language
  note.time_complexity:
    displayName: TC
  note.space_complexity:
    displayName: SC
views:
  - type: table
    name: Solutions & Notes
    filters:
      and:
        - file.hasLink(this.file)
        - file.tags.containsAny("leetcode/solution", "leetcode/note")
    order:
      - file.name
      - desc
      - program_language
      - time_complexity
      - space_complexity
      - grade
      - relative_links
      - updated
    sort:
      - property: grade
        direction: ASC
      - property: time_complexity
        direction: ASC
      - property: program_language
        direction: ASC
    columnSize:
      file.name: 104
      note.space_complexity: 65
      note.grade: 126
 

Similar Problems

properties:
  note.lcTopics:
    displayName: Topics
  note.lcAcRate:
    displayName: AC Rate
  note.favorites:
    displayName: Favorites
  note.grade:
    displayName: Rating
  note.translatedTitle:
    displayName: Title (CN)
  note.lcDifficulty:
    displayName: Difficulty
views:
  - type: table
    name: Similar Problems
    filters:
      and:
        - file.hasLink(this.file)
        - similarQuestions.contains(this.file)
    order:
      - file.name
      - translatedTitle
      - lcTopics
      - lcDifficulty
      - lcAcRate
      - grade
      - favorites
    sort:
      - property: file.name
        direction: ASC
      - property: lcTopics
        direction: DESC
    columnSize:
      note.translatedTitle: 240
      note.lcTopics: 347
      note.lcAcRate: 75
      note.grade: 122