如何使用SED更换[]支架 [英] How do i replace [] brackets using SED

查看:73
本文介绍了如何使用SED更换[]支架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要删除标点符号的字符串.

I have a string that i am want to remove punctuation from.

我从

sed 's/[[:punct:]]/ /g'

但是我在HP-UX上遇到的问题不是一直都这样,有时在字符串中的$之后我会得到0和任何东西,但该内容会消失.所以我决定尝试手动进行.

But i had problems on HP-UX not liking that all the time, and some times i would get a 0 and anything after a $ in my string would dissappear. So i decided to try to do it manually.

我有以下代码可用于我感兴趣的所有标点符号,除了我似乎无法用其他任何东西在我的sed中添加方括号"[]",否则它不会替代任何东西,而且我不会得到错误,所以我不确定要解决什么.

I have the following code which works on all my punctuation that I am interested in, except I cannot seem to add square brackets "[]" to my sed with anything else, otherwise it does not replace anything, and i dont get an error, so I am not sure what to fix.

无论如何,这是我目前拥有的,并且想要添加[].

Anyways this is what i currently have and would like to add [] to.

sed 's/[-=+|~!@#\$%^&*(){}:;'\'''\"''\`''\.''\/''\\']/ /g'

顺便说一句,我在Solaris,Redhat和amp;上使用KSH.惠普

BTW I am using KSH on Solaris, Redhat & HP

推荐答案

这是我最后得到的最终代码

Here is the final code I ended up with

`echo "$string" | sed 's/[^a-zA-Z0-9]/ /g'`

我必须将=-放在最后.

这篇关于如何使用SED更换[]支架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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