linux - Sed is truncating first character if it is starting with "v" while appending in file
问题描述
I am stuck in one of my production code where I am trying to append some content at the start of file and if the content which I want to append is starting with "v" , its getting truncated.
Steps to reproduce:
$ cat text.txt
Kubernetes document
$ var1=version1
$ sed -e "s/^/\\${var1} /" text.txt
Output:
ersion1 Kubernetes document
Desired Output:
version1 Kubernetes document
解决方案
Your use of the backslash is wrong. Check this:
var1=version1
echo "s/^/\\${var1} /"
Your escaping leads to the following sed command:
s/^/\version1 /
\v
is a special char: vertical tab, which is not visible on your terminal.
The simple solution is to not escape at all, it's simply not needed when interpolating variables into a double quoted string:
sed -e "s/^/\\${var1} /" text.txt
推荐阅读
- asp.net-core - asp.net core web api本地https问题
- autocomplete - PhpStorm - li [TAB] 使用“link”元素而不是“li”元素自动完成
- excel - 如何知道我的加载项已在 Excel 任务窗格 Office 365 中打开?
- java - 即使说已连接到应用程序,Firebase 数据插入也无法正常工作
- amazon-web-services - 如何为没有域的后端 EC2 实例使用 SSL
- java - 无法使用 FTPSClient 通过 FTP 服务器传输数据 - 连接被拒绝
- puppeteer - Chrome 无头加载页面与普通 Chrome 不同
- python - 如何在 scikit-learn 管道中将时代添加到 Keras 网络
- arrays - 数组转换为小写后单词的索引发生变化,并保存为新列表
- continuous-integration - GITLAB CI 管道未触发