[英]How to keep the double quotes in double quotes using sed
For example,例如,
echo "hello, mon saids "I am tired", Sorry"
The result is :结果是:
hello, mon saids I am tired, Sorry
The expected result:预期结果:
hello, mon saids "I am tired", Sorry
I know we can use我知道我们可以使用
echo "hello, mon saids \"I am tired\", Sorry"
But I suppose to do this in one file or many files, cannot manually insert \\ to every ". Could you provide a way to do this using sed?但是我想在一个文件或多个文件中执行此操作,无法手动将 \\ 插入到每个 "。您能否提供一种使用 sed 执行此操作的方法?
You can use single quotes around the string as following:您可以在字符串周围使用单引号,如下所示:
echo 'hello, mon saids "I am tired", Sorry'
This way, the inner double quotes will be preserved without the need to escape them with backslashes.这样,内部双引号将被保留,而无需用反斜杠将它们转义。
I understand that using single quotes as suggested may work, so using this sed may help我知道按照建议使用单引号可能会起作用,因此使用此 sed 可能会有所帮助
sed -E "s/(^.)|(.$)/'/g"
This can help to shift the first and the last double quotes to single ones.这有助于将第一个和最后一个双引号转换为单引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.