Bash 如何将字符串附加到给定行的开始和结束处
对于文档需求,我有一个shell脚本,其中我必须在给定行的shell脚本的开头和结尾添加特定字符串,行号是随机的,并且包含在列表中Bash 如何将字符串附加到给定行的开始和结束处,bash,shell,Bash,Shell,对于文档需求,我有一个shell脚本,其中我必须在给定行的shell脚本的开头和结尾添加特定字符串,行号是随机的,并且包含在列表中 for example :- test.sh line number := 2,5,6,7,9 Add ">" "/>" in test.sh file go to the line number 2 and add ">" in the start of the line and "/>" at the en
for example :-
test.sh
line number := 2,5,6,7,9
Add ">" "/>"
in test.sh file go to the line number 2 and add ">" in the start of the line and "/>" at the end of the line do the same for line number 5,6,7,9
在awk中,您可以测试
NR
是否在patsplit()
返回的行号数组中
这里
2
是行号<代码>“\>”和“\\>”
分别是前缀和后缀(您需要转义&
和\
)。您将有一个后缀为~
patsplit()
的备份文件需要GNU AWK(gawk
)版本4。这是家庭作业吗?您尝试了什么?您的示例代码不是有效的Bash。您可以通过编写一些有效的Bash来提高问题的质量,尝试解决您的问题,然后用一个特定的问题更新您的原始帖子,而不是请求其他人为您编写脚本。@DennisWilliamson谢谢没有作业,我在寻找提示
sed -i~ '2{s/^.*$/"\>"&"\\\>"/}' FILE