SED替换行号模式 [英] Sed replace pattern with line number
问题描述
我需要更换模式 ###
与当前的行号。
I need to replace the pattern ###
with the current line number.
我设法与两个AWK和SED下一行打印。
I managed to Print in the next line with both AWK and SED.
SED -n/ ### / {磷; =;}文件
打印到下一行,而不磷;
,它取代了整条生产线。
sed -n "/###/{p;=;}" file
prints to the next line, without the p;
, it replaces the whole line.
SED -eS / ### / {=;} / g的文件
用于道理在我的头上,因为 =;
返回匹配模式的行号,但它会返回我的文字 {=;}
sed -e "s/###/{=;}/g" file
used to make sense in my head, since the =;
returns the line number of the matched pattern, but it will return me the the text {=;}
我在想什么?我知道这是一个愚蠢的问题。我找不到答案的sed的手册中的这个问题,不是很清楚。
What am i Missing? I know this is a silly question. I couldn't find the answer to this question in the sed manual, it's not quite clear.
如果可能的话,指出我什么我失踪了,什么使它工作。谢谢
If possible, point me what was i missing, and what to make it work. Thank you
推荐答案
简单 AWK
oneliner:
Simple awk
oneliner:
awk '{gsub("###",NR,$0);print}'
这篇关于SED替换行号模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!