bash - grep 不能很好地搜索双引号。甚至没有\"
问题描述
- 在 Ubuntu 16.04 *
我有一个包含以下行的文件:
s:15:\"https://cnn.com\"
cat myfile.txt | grep https://cnn.com
作品。
但我也想找到这s:15
部分,所以我尝试:
cat myfile.txt | grep 's:15:\"https://cnn.com\"'
零结果。我究竟做错了什么?
解决方案
您的命令的问题不是引号而是反斜杠。由于原始文件中有反斜杠,因此您也需要将反斜杠与 grep 匹配(因此,将它们转义):
$ cat myfile.txt | grep 's:15:\\"https://cnn.com\\"'
s:15:\"https://cnn.com\"
推荐阅读
- c# - 如何将这种类型的 Json 反序列化为 C# 对象
- uwp - Win2d中CanvasBitmap和CanvasVirtualBitmap有什么区别?
- c# - 实体类型 CST_Parameter 不是当前上下文模型的一部分
- ibm-cloud - IBM api connect 是否支持 POST multipart/form-data 请求?
- html - 我的导航栏列表元素正在移动到下一行,如何定位它们以适合单行?
- entity-framework - 实体框架核心,无法在 PrimaryKey 上设置 HasName
- java - 为什么将变量分配给自身会提示 Intellij 想法的更正
- android - 使用 postgresql 在 android studio (kotlin) 中插入记录
- navigation - 无法从导航栏 Swift UI 导航到第二个视图
- firebase - firestore - request.path 在模拟器中未定义