如何在sed中用另一个字符替换单引号? [英] How do I replace single quotes with another character in sed?

查看:300
本文介绍了如何在sed中用另一个字符替换单引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个平面文件,其中多次出现包含单引号的字符串,例如hari'sleader's.

I have a flat file where I have multiple occurrences of strings that contains single quote, e.g. hari's and leader's.

我想用空格替换所有出现的单引号,即

I want to replace all occurrences of the single quote with space, i.e.

  • 所有从hari'shari s的事件
  • leader'sleader s
  • 的所有出现
  • all occurences of hari's to hari s
  • all occurences of leader's to leader s

我尝试过

sed -e 's/"'"/ /g' myfile.txt

sed -e 's/"'"/" "/g' myfile.txt

但是他们没有给我预期的结果.

but they are not giving me the expected result.

推荐答案

尝试使sed命令尽可能简单. 否则,您会为以后阅读的内容感到困惑.

Try to keep sed commands simple as much as possible. Otherwise you'll get confused of what you'd written reading it later.

#!/bin/bash
sed "s/'/ /g" myfile.txt

这篇关于如何在sed中用另一个字符替换单引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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