使用sed只获取"grep -in"的行号

Wra*_*Lux 3 regex bash sed

我应该使用哪个正则表达式只从grep -in输出中获取行号?通常的输出是这样的:241113:关键字

我需要从sed的输出中得到"241113".

seh*_*ehe 7

我建议切

 grep -in keyword ... | cut -d: -f1
Run Code Online (Sandbox Code Playgroud)

如果你坚持使用sed:

 grep -in keyword ... | sed 's/:.*$//g
Run Code Online (Sandbox Code Playgroud)