使用 sed 时如何转义双引号?
我正在尝试删除包含双引号的所有文本行,并且我已经尝试过:sed -ne '/\"/!p' theinput > theproduct
它使线条保持不变。我该怎么办?这是我的脚本: `触摸tmp.txt 打开tmp.txt read -sn 1 -p "粘贴数据并按任意键进行转换" echo
touch tmp.txt
open tmp.txt
read -sn 1 -p "Paste in data and press any key to convert"
echo
sed -e 's/-/ /g' tmp.txt > tmp2.txt
grep -v '"' tmp2.txt > final.txt
open final.txt
echo Study Conversion Successful
第一个 sed 命令有效。它用一堆空格替换连字符(不要问我为什么需要它)。我从响应中添加的 grep 命令不起作用。它使带引号的行保持不变。
I'm trying to remove all lines of text that contain a double quote, and I have tried this:sed -ne '/\"/!p' theinput > theproduct
It left the lines untouched. What do I do? Here is my script:
`touch tmp.txt
open tmp.txt
read -sn 1 -p "Paste in data and press any key to convert"
echo
touch tmp.txt
open tmp.txt
read -sn 1 -p "Paste in data and press any key to convert"
echo
sed -e 's/-/ /g' tmp.txt > tmp2.txt
grep -v '"' tmp2.txt > final.txt
open final.txt
echo Study Conversion Successful
The first sed command works. It replaces a hyphen with a bunch of spaces (don't ask why I need that). The grep command, which I added from a response, does not work. It leaves the lines with quotes untouched.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有必要转义双引号:
Its not necessary to escape the double quote:
很奇怪。它“对我有用”
也许是 sed 的版本问题?
但是,您也可以考虑使用 grep -v 来实现此目的。
Very strange. It "works for me"
Perhaps it is a version issue with
sed
?However, you can also consider using
grep -v
for this.