{ "data": { "question": { "questionId": "193", "questionFrontendId": "193", "categoryTitle": "Shell", "boundTopicId": 1335, "title": "Valid Phone Numbers", "titleSlug": "valid-phone-numbers", "content": "
Given a text file file.txt
that contains a 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)
\n\nYou may also assume each line in the text file must not contain leading or trailing white spaces.
\n\nExample:
\n\nAssume that file.txt
has the following content:
\n987-123-4567\n123 456 7890\n(123) 456-7890\n\n\n
Your script should output the following valid phone numbers:
\n\n\n987-123-4567\n(123) 456-7890\n\n", "translatedTitle": "有效电话号码", "translatedContent": "
给定一个包含电话号码列表(一行一个电话号码)的文本文件 file.txt
,写一个单行 bash 脚本输出所有有效的电话号码。
你可以假设一个有效的电话号码必须满足以下两种格式: (xxx) xxx-xxxx 或 xxx-xxx-xxxx。(x 表示一个数字)
\n\n你也可以假设每行前后没有多余的空格字符。
\n\n\n\n
示例:
\n\n假设 file.txt
内容如下:
\n987-123-4567\n123 456 7890\n(123) 456-7890\n\n\n
你的脚本应当输出下列有效的电话号码:
\n\n\n987-123-4567\n(123) 456-7890\n\n", "isPaidOnly": false, "difficulty": "Easy", "likes": 153, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", "topicTags": [ { "name": "Shell", "slug": "shell", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "Bash", "langSlug": "bash", "code": "# Read from the file file.txt and output all valid phone numbers to stdout.", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"41.7K\", \"totalSubmission\": \"124.8K\", \"totalAcceptedRaw\": 41736, \"totalSubmissionRaw\": 124834, \"acRate\": \"33.4%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "0", "metaData": "{\n \"shell\": true,\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": false, "envInfo": "{\"bash\":[\"Bash\",\"
\\u7248\\u672c\\uff1aBash 4.3.30<\\/code><\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "0",
"__typename": "QuestionNode"
}
}
}