unix - How to search a string containing with $ and ; in linux
问题描述
I ran a ldapsearch command and the output is redirected to a file(overwriting the same file every time the command is run) I have to search 3 strings, In which have 2 strings have $ and ; in it.
Contents in the file example.txt
<some lines above>
changenumber;demo$host-example_good1$fine-example_good2
changenumber;echo$fine-example_good2$host-example_good1
changenumber;echo$host-example_good1$fine-example_good2
changenumber;demo$fine-example_good2$host-example_good1
<some lines below>
<end of file>
Tried below commands
awk -F";|$" '/echo$host-example_good1$fine-example_good2'/ example.txt
awk -F"[$;]" '/demo$host-example_good1$fine-example_good2'/ example.txt
Output: nothing is displayed
Expected output
changenumber;demo$host-example_good1$fine-example_good2
changenumber;echo$host-example_good1$fine-example_good2
解决方案
$
在正则表达式中有特殊含义,需要转义。
awk -F'[;$]' '/demo\$host-example_good1\$fine-example_good2/' example.txt
转到regular-expressions.info阅读有关正则表达式的教程。
推荐阅读
- ruby-on-rails - 使用 Rspec 和 FactoryBot 进行 Rails 测试
- function - 通过 Scheme 对列表中的所有元素进行平方
- c# - 如何在不创建临时文件的情况下将嵌入式资源 JSON 文件添加到 ConfigurationBuilder?
- javascript - javascript中for循环的计数器
- javascript - 从 Chrome 扩展创建和管理类电子窗口
- aws-lambda - 无服务器框架 - 为 dynamodb 设置资源权限
- java - 如何为我的前缀匹配器算法找到更好的算法
- android - 在生成带有颤振应用程序崩溃的构建并且未打开之后
- javascript - 在 Webpack 中的多个条目之间加载共享资产
- python - 如何在 Tkinter 中创建具有给定半径的圆?