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"