我试图用sed命令清除一个txt文件中的所有字符怪异:删除文本文件
sed -i.bak -e '[email protected]^[A-Za-z0-9_.;,:][email protected]@g' *.txt
回报
sed: RE error: illegal byte sequence
我在做什么毛病经常EXP?通常,我说 “全部替换不是A-ZA-Z0-9 _;,:” 有 “”
我试图用sed命令清除一个txt文件中的所有字符怪异:删除文本文件
sed -i.bak -e '[email protected]^[A-Za-z0-9_.;,:][email protected]@g' *.txt
回报
sed: RE error: illegal byte sequence
我在做什么毛病经常EXP?通常,我说 “全部替换不是A-ZA-Z0-9 _;,:” 有 “”
你把^
@不好的地方,把它放在那里:
sed -i.bak -e '[email protected][^A-Za-z0-9_\.;,:]\[email protected]@g' *.txt
,而不是小的变化(backslashing一些特殊字符)
你正在运行哪个操作系统? – 2014-12-11 00:37:43
我使用的是Mac OS – Michele 2014-12-11 00:44:14
正在使用-E而不是-e帮助吗? – 2014-12-11 00:46:58
比方说您有一个名为“my_file”的文件这样的事情
Location: http://www.google.gy/?gws_rd=cr&ei=l_KIVOXnIsinNq2NgsgB [following]
--2014-12-10 21:25:44-- http://www.google.gy/?gws_rd=cr&ei=l_KIVOXnIsinNq2NgsgB
Resolving www.google.gy (www.google.gy)... 64.233.176.94, 2607:f8b0:4002:c05::5e
Connecting to www.google.gy (www.google.gy)|64.233.176.94|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html.2'
你可以试试
sed -i.bak -e 's#[^[:alnum:].;,:]##g' 'my_file'
这将查找非字母数字或“。”或“;”或“,”或“:”并打印的字符。 结果
Location:http:www.google.gygwsrdcreilKIVOXnIsinNq2NgsgBfollowing
2014121021:25:44http:www.google.gygwsrdcreilKIVOXnIsinNq2NgsgB
Resolvingwww.google.gywww.google.gy...64.233.176.94,2607:f8b0:4002:c05::5e
Connectingtowww.google.gywww.google.gy64.233.176.94:80...connected.
HTTPrequestsent,awaitingresponse...200OK
Length:unspecifiedtexthtml
Savingto:index.html.2
格伦·杰克曼是正确的,在帮助其他职位找到了解决办法...
唯一的问题就是命令现在只知道英语拉丁字符所以将无法正常工作......
这里的结果,什么都没有改变:
ÁÉc†ÿ°“Å9,0,sub,,0,0,0,,Pero, aun no comprendo porque quer√≠a acabar conÄC∂u⁄ÁÉx¨†ú°ñÅ996,0,sub,,0,0,0,,õÇ–†µ°ØÅ*10,0,sub,,0,0,0,,Ha deshonrado aléC∂u⁄ÁÉ©≤†”°ÕÅ11,0,sub,,0,0,0,,{\pos(1481.142,795.974)\bord0\fad(800,0)}Himalayan RangeõÇ!¸C∂[email protected]óÁÉf†”°ÕÅ12,0,sub,,0,0,0,,¬øEsta seguro que querer hacerlo solo?, se√±or MitsumazaõÇ»†ª°µÅî13,0,sub,,0,0,0,,Silencio Tatsumi, tranquil√≠zateõÇ2C∂[email protected]ôÁÉ,†©°£Å14,0,sub,,0,0,0,,Pero se√±or...õÇ\†≠°ßÅ\15,0,sub,,0,0,0,,Aunque lo digas...õÇ<†∏°≤Åò16,0,sub,,0,0,0,,Tengo un esp√≠ritu aventureroõÇ|C∂[email protected]£ÁÉ@†∞°™Å17,0,sub,,0,0,0,,Lo entiendo se√±or...õÇ–†≤°¨Å–18,0,sub,,0
您可能想要使用一些POSIX为清楚起见字符类名(?):'SED -i.bak -e“S/[^ [:alnum:] [:punct:] [:blank:]] // g'* .txt' - 你知道你也在删除空格和制表符? – 2014-12-11 00:53:33
[RE错误:Mac OS X上的非法字节序列]的可能重复(http://stackoverflow.com/questions/19242275/re-error-illegal-byte-sequence-on-mac-os-x) – 2014-12-11 00:54:51
哦,是的,我如何保持空间? – Michele 2014-12-11 01:19:52