So this should be easy, but I just can't seem to get it right. I have the following data:
所以这应该很容易,但我似乎无法做到正确。我有以下数据:
4131942 Door Assy, LH Ref 249R/RP
15 #7002668 - Rev. A - June, 2006
1. 6110010 Bolt, #10-24 x 1/2” Flat Head
and I want to delete the middle line.
我想删除中间行。
This is the most recent iteration of the statement that I am using:
这是我正在使用的语句的最新迭代:
sed -i '/(^[(0-9)][(0-9)](.*)[#][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)](.*))/d'
I have used multiple variation and different regexps, to no avail.
我使用了多种变体和不同的正则表达式,但无济于事。
What am I missing here?
我在这里想念的是什么?
1 个解决方案
#1
1
Your regex is ok, but you need to use sed -r
in order to enable extended regular expressions.
你的正则表达式没问题,但你需要使用sed -r来启用扩展的正则表达式。
Try:
sed -ri '/(^[(0-9)][(0-9)](.*)[#][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)](.*))/d' file
Alternatively, simplify it to:
或者,将其简化为:
sed -ri '/^[0-9]{2}.*#[0-9]{7}.*/d' file
#1
1
Your regex is ok, but you need to use sed -r
in order to enable extended regular expressions.
你的正则表达式没问题,但你需要使用sed -r来启用扩展的正则表达式。
Try:
sed -ri '/(^[(0-9)][(0-9)](.*)[#][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)][(0-9)](.*))/d' file
Alternatively, simplify it to:
或者,将其简化为:
sed -ri '/^[0-9]{2}.*#[0-9]{7}.*/d' file