我有一个包含一些行的文件 这些行看起来像这样:
zadde205554800156569001
sfsdf848532300258112668
fsdfs552258800556220056
.
.
.
dzaed686745800158748048
我希望从第13列开始只使用一些awk和正则表达式来获取包含001
和005
的行
所以输出应该是这样的:
zadde205554800156569001
fsdfs552258800556220056
dzaed686745800158748048
我尝试了一些grep命令,但徒劳无功
答案 0 :(得分:1)
^.{12}(?:001|005)
此正则表达式将执行以下操作:
001
或005
现场演示
https://regex101.com/r/lQ2oD6/1
示例文字
zadde205554800156569001
sfsdf848532300258112668
fsdfs552258800556220056
.
.
.
dzaed686745800158748048
样本匹配
zadde205554800156569001
fsdfs552258800556220056
dzaed686745800158748048
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
.{12} any character except \n (12 times)
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
001 '001'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
005 '005'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
答案 1 :(得分:0)
$ awk '/.{12}00[15]/' file
zadde205554800156569001
fsdfs552258800556220056
dzaed686745800158748048
$ grep -E '.{12}00[15]' file
zadde205554800156569001
fsdfs552258800556220056
dzaed686745800158748048
$ sed -E -n '/.{12}00[15]/p' file
zadde205554800156569001
fsdfs552258800556220056
dzaed686745800158748048