如何使用 && 等特殊字符执行 SED 命令和 '/' 用于搜索和替换? [英] How to perform SED command with Special character like && and '/' for search and Replace?

查看:59
本文介绍了如何使用 && 等特殊字符执行 SED 命令和 '/' 用于搜索和替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有像 && 这样的搜索字符串!this.peekStartsWith('//') 并想用空格替换 .我试过了

I have search string like && !this.peekStartsWith('//') and want to replace with blank space . I have tried

sed -i 's/&& !this.peekStartsWith('\/\/')/ /g' dist/vendor.bundle.js

但是,得到像

bash: !this.peekStartsWith: 事件未找到

bash: !this.peekStartsWith: event not found

有人可以帮忙解决这个问题吗?

Can anyone help to work around this?

推荐答案

我只在逃避 !

sed "s|&& \!this\.peekStartsWith('//')| |g" file

示例文件

cat file
some data&& !this.peekStartsWith('//')more data

测试

sed "s|&& \!this\.peekStartsWith('//')||g" file
some datamore data
sed "s|&& \!this\.peekStartsWith('//')| |g" file
some data more data
sed "s|&& \!this\.peekStartsWith('//')|***|g" file
some data***more data

这篇关于如何使用 && 等特殊字符执行 SED 命令和 '/' 用于搜索和替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆