管道分类为sed,在记录末尾匹配5位或更多位数?

eve*_*veo 0 unix shell

文件

plym    fury    77      73      2500
chevy   nova    79      60      3000
ford    mustang 65      45      17000
volvo   gl      78      102     9850
ford    ltd     83      15      10500
Chevy   nova    80      50      3500
fiat    600     65      115     450
honda   accord  81      30      6000
ford    thundbd 84      10      17000
toyota  tercel  82      180     750
chevy   impala  65      85      1550
ford    bronco  83      25      9525
Run Code Online (Sandbox Code Playgroud)

我必须删除10,000美元或更多的所有汽车(文件的最后一栏).我必须通过在记录结尾处表示代表5位或更多位的正则表达式时退出来将排序的输出传输到sed中.

这是我必须管道的命令: grep -iv chevy cars | sort -nk 5

我到目前为止尝试过:

grep -iv chevy cars | sort -nk 5 | sed -n '/[0-9]{5}*/'

但无济于事.


So far we have:

grep -iv chevy cars | sort -nk 5

Now let's delete the cars that are $10,000 or more.  Pipe the output of the sort into
a sed to do this, by quitting as soon as we match a regular expression representing 5
(or more) digits at the end of a record (DO NOT use repetition for this):

You entered: grep -iv chevy cars | sort -nk 5 | sed -n '/[0-9]{5}$/'
Please try again.
Run Code Online (Sandbox Code Playgroud)

And*_*son 5

使用-n开关,您必须明确地使用p匹配线,并!p打印非加工线,即不花费5位数值的汽车.也添加$到图案仅在端部相匹配,并且逃逸\{\}用于重复组,否则会匹配文字串{5}一个数字之后.

试试这个: sed -n '/[0-9]\{5\}$/!p'

如果要在第一个匹配时退出而不是仅打印相关匹配,请尝试使用q命令而不是!p.