valid phone numbers

2018-9-4 杜世伟 awk

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.

Example:

Assume that file.txt has the following content:

987-123-4567
123 456 7890
(123) 456-7890
Your script should output the following valid phone numbers:

987-123-4567
(123) 456-7890

cat > file.txt <<EOF
987-123-4567
(123) 456-7890
0(001) 345-0000
(001) 123-345

阅读全文>>

标签: linux grep awk

评论(0) 浏览(2527)

linux awk 改变文件的内容的分隔符并添加行号

2013-6-9 杜世伟 awk

linux awk 改变文件的内容的分隔符并添加行号以下是范例内容,使用‘,’分隔符
$ cat testfile.out
3232,32332,54545,34
3233,45645,23233,23
1211,1212,4343,434
3434,121121,121,33
替换文件内容中,为|并且为每行添加新的行号,输出结果为:
1|3232|32332|54545|34
2|3233|45645|23233|23
3|1211|1212|4343|434
4|3434|121121|121|33

阅读全文>>

标签: linux tr awk

评论(0) 浏览(7938)

linux 合并多个连续的行

2013-6-8 杜世伟 awk

linux 合并多个连续的行
文件内容为:
$ cat infile.txt 
aid=33
pw=3
nn=90
aid=32
pw=30
nn=70
aid=56
pw=3
nn=93

组合或合并上述文件的每三个连续行,使输出变为:
aid=33,pw=3,nn=90
aid=32,pw=30,nn=70
aid=56,pw=3,nn=93

阅读全文>>

标签: linux awk bash read

评论(0) 浏览(14307)

linux 将0附加到单位数字日期

2013-6-8 杜世伟 awk

linux 将0附加到单位数字日期
日期的文件格式为:month/day/year format. 
$ cat date.txt 
3/4/2013
3/10/2013
10/4/2013
12/10/2012
要求将0附加到单位数字日期,输入格式为
03/04/2013
03/10/2013
10/04/2013
12/10/2012

阅读全文>>

标签: linux awk

评论(0) 浏览(3876)

Powered by emlog 沪ICP备2023034538号-1