Valid Phone Numbers(leetcode193-t5.sh)

38 篇文章 0 订阅
22 篇文章 0 订阅

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 phone-t5.txt has the following content:
134-1056-4490
590-2901-989
10-118
190-2020-2
a-1103
190-2234-8903
199-2-a
19910003
Your script should output the following valid phone numbers:
134-1056-4490
190-2234-8903

#!/bin/bash
sed -n -r '/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/p' phone-t5.txt

输出结果:

root@ubuntu:~# ./test.sh 
134-1056-4490
190-2234-8903
awk '$1 ~ /^[0-9]{3}-[0-9]{4}-[0-9]{4}$/  { print }' phone.txt
#sed -n -r '/^[0-9]{3}-[0-9]{4}-[0-9]{4}$/p' phone.txt

执行输出不对,The reason it did not work is because it was using mawk as the interpreter (which came as the default in Ubuntu)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
三态门是一种在Verilog常用的逻辑门,用于实现双向接口。三态门的工作原理是通过控制信号来控制门的开关状态,从而实现数据的输入和输出。当控制信号为1时,门处于高阻态,输出为高阻态;当控制信号为0时,门开通,输入信号可以通过门传递。在Verilog三态门可以使用module来描述,具体的代码描述如下所示: module v_three_st_2 (T, I, O); input T, I; output O; assign O = (~T) ? I: 1'bZ; endmodule 在这段Verilog代码,T表示控制信号,I表示输入信号,O表示输出信号。当T为1时,O处于高阻态;当T为0时,O等于输入信号I。根据控制信号T是高有效还是低有效,三态门的行为会有所不同。根据上述代码描述的逻辑,当T为1时,O处于高阻态,对应于输入端口;当T为0时,O等于输入信号I,对应于输出端口。 三态门Verilog常用于双向接口,比如FLASH的数据接口。在写入数据时,数据接口作为输出端口接收FLASH控制器传来的数据;在读取数据时,数据接口作为输入端口,将从FLASH内部读取的数据传递给FLASH控制器。这种双向接口可以通过使用三态门实现。 总结起来,三态门是一种在Verilog常用的逻辑门,用于实现双向接口。通过控制信号来控制门的开关状态,从而实现数据的输入和输出。在编写三态门Verilog代码时,需要根据实际情况确定控制信号的有效性,同时保证与原语保持一致。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [2022-5-20](https://blog.csdn.net/A15619228315/article/details/124881909)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [verilog三态门用法](https://blog.csdn.net/qq_47891174/article/details/122005422)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值