开发者

use sed to replace a line

开发者 https://www.devze.com 2023-02-23 06:07 出处:网络
I have been struggling to do this. I need to replace a line in a document with either blank space or the word \"DELETED.\" The lines are different, and I am running a counter to determine the correct

I have been struggling to do this. I need to replace a line in a document with either blank space or the word "DELETED." The lines are different, and I am running a counter to determine the correct line to replace. So far, I have been using:

sed -ie ''$NUMLINE's/^$/DELETED/' Brown_Adam_CIVForms.txt 

I would like to replace the 开发者_开发知识库NUMLINE-th line from this document (whatever it may be) and replace it with either blank space or the word "DELETED." Please help!!

Thank you!!!


Just insert .* between ^ and $. Like:

sed -ie $NUMLINE's/^.*$/DELETED/' Brown_Adam_CIVForms.txt 


you can also use awk

awk -vnum=$NUMLINE 'NR==num{$0="DELETED"}1' file
0

精彩评论

暂无评论...
验证码 换一张
取 消