用bash脚本替换一行 [英] replace a line with bash script

查看:49
本文介绍了用bash脚本替换一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试替换文件的一行.我用

I am trying to replace a line of my file. I used

line=" abc"
sed -i "3c ${line}" test.txt

它可以工作,但是第一个空格没有出现.我希望test.txt中的第3行是

It works but the first space doesn't show up. I want the line 3 in test.txt to be

 abc

而不是

abc

请注意, abc 前面有一个空格.感谢您的任何建议!

notice there is a space before abc. thanks for any suggestions!

推荐答案

line="\ abc"
sed -i "3c\
$line" test.txt

转义空间可以防止修剪.

Escaping the space will keep it from being trimmed.

这篇关于用bash脚本替换一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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