Bash:使用带有可变行号的sed,并在行替换中使用变量 [英] Bash: using sed with a variable line number, and variables in the line replacement

查看:458
本文介绍了Bash:使用带有可变行号的sed,并在行替换中使用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我看到了这个问题:替换从变量中获取数字的完整行 这非常相似,但是在我的情况下,我尝试使用多个变量:一个用于行号[lineNo],一个用于替换[transFormatted]的文本以及它应在[OUTPUT_FILE]中查找的文件, ve尝试了数十种组合以尝试使其识别所有这些变量,但似乎无济于事.不管我尝试哪种方式,这都是不快乐的.我在做什么错了?

So I have seen this question: Replace complete line getting number from variable which is pretty similar, but in my case I am trying to use multiple variables: one for the line number [lineNo], one for the text to replace [transFormatted] and the file to which it should be looking in [OUTPUT_FILE] I've tried dozens of combinations to try to get it to recognize all these variables but nothing seems to work. It's unhappy no matter which way I try. What am I doing wrong?

sed -e '${lineNo}s/.*/${transFormatted}/' < $OUTPUT_FILE

推荐答案

单引号禁止参数扩展.

sed -e "${lineNo}s/.*/$transFormatted/" < "$OUTPUT_FILE"

这篇关于Bash:使用带有可变行号的sed,并在行替换中使用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆