如何强制 emacs(或任何编辑器)像 ASCII 格式一样读取文件?
我无法在 man
或 info
页面中找到这个答案,也无法在此处或 Google 上进行搜索。我有一个文件,本质上是一个文本文件,但在保存时不知何故搞砸了。 (我认为文件前面意外地出现了一些奇怪的字节。)
我可以使用 head
或 cat
打开该文件,并且这是有意义的,但不使用任何类型的编辑器。
最后,我想做的就是在emacs中打开文件,删除“乱”字符,清理干净后保存。然而,该文件巨大,因此我需要像 emacs 这样强大的东西才能打开它。
否则,我想我可以尝试创建一个脚本来逐行读取它,强制脚本以文本格式读取它,然后写入它。但我想要快一点,因为我不会重复做这件事。超过。
谢谢! 麦克风
I could not find this answer in the man
or info
pages, nor with a search here or on Google. I have a file which is, in essence, a text file, but it somehow got screwed up upon saving. (I think there are a few strange bytes at the front of the file accidentally.)
I am able to open the file, and it makes sense, using head
or cat
, but not using any sort of editor.
In the end, all I wish to do is open the file in emacs, delete the "messy" characters, and save it once cleaned up. The file, however, is huge, so I need something powerful like emacs to be able to open it.
Otherwise, I suppose I can try to create a script to read this in line by line, forcing the script to read it in text format, then write it. But I wanted something quick, since I won't be doing this over & over.
Thanks!
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在这里找到了这个 Perl One 衬垫: http://www.perlmonks.org/?node_id=619792
Found this perl one liner here: http://www.perlmonks.org/?node_id=619792
在 Emacs 中尝试 Mx
find-file-literally
。Try M-x
find-file-literally
in Emacs.您可以使用 hexl-mode,它允许您以十六进制编辑文件。这可以让你准确地看到那些有问题的字符是什么,并将它们删除。
听起来您要么在文件中以不同的行结尾(例如:*nix 系统上的回车符),要么以意外的编码保存。
You could edit the file using hexl-mode, which lets you edit the file in hexadecimal. That would let you see precisely what those offending characters are, and remove them.
It sounds like you either got a different line ending in the file (eg: carriage returns on a *nix system) or it got saved in an unexpected encoding.
您可以使用
strings
来获取“文件中的可打印字符”。您可能需要使用--encoding
虽然我只用它来从可执行文件中获取 ascii 字符串。You could use
strings
to grab "printable characters in file". You might have to play with the--encoding
though I have only ever used it to grab ascii strings from executable files.