如何防止SED改变线路断路?
我正在用.js
文件更改.sh
文件的内容,但是有不必要的副作用。
。
# update file
version="0.1"
file="Test.js"
updated_line="const version = \"$version\";"
sed -i "1s/.*/$updated_line/" $file
const version = "0";
const moreVars = {};
在离开线路破裂时,我该如何进行这些更改?
I am changing content of a .js
file with a .sh
file but there's an unwanted side-effect.
.sh file:
# update file
version="0.1"
file="Test.js"
updated_line="const version = \"$version\";"
sed -i "1s/.*/$updated_line/" $file
Test.js file:
const version = "0";
const moreVars = {};
After running the .sh file the update seems to be successfull but my IDE is complaining that the linebreaks changed from CRLF
to LF
:
How can I make these changes while leaving the linebreaks the way they were?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
sed
并不是line break意识到,从这个意义上说,cr字符只是cr字符。如果您希望自己的行具有CR角色,则必须添加CR字符。对于SED,它只是一个像其他人一样的角色。写一个正则态度,如果存在并保留线条末端的CR字符。
sed
is not linebreak aware, in that sense, CR character is just that CR character. If you want your line to have CR character, you have to add CR character. For sed it's just a character like any other.Write a regex that matches CR character on the end of the line if it exists and preserve it.