为什么 Strawberry Perl 不删除这些换页字符?
我目前正在 WinXP 上运行 Strawberry Perl,并且正在尝试处理 unix 格式的平面文件。平面文件使用换行符来分隔字段,并使用换页符来分隔记录。我正在尝试将 FF 转换为其他任何内容(CRLF、';'、TAB 等)。我尝试使用以下 perl 单行代码,但没有成功:
perl -p -e 's/\f/\r\n/g' < unix.txt > dos.txt
perl -p -e 's/\x0c/\x0d\x0a/g' < unix.txt > dos.txt
perl -p -e 's/\f/\t/g' < unix.txt > dos.txt
我注意到的唯一一件事是 dos.txt 最终将所有 LF 字符转换为 CRLF,但 FF 字符仍然存在。我什至尝试重新处理 dos.txt 文件,再次尝试替换 FF,但仍然没有骰子。我仍然是一个 Perl 新手,所以也许我错过了一些东西?有谁知道为什么上述命令不执行我想要的操作?
I'm currently running Strawberry Perl on WinXP, and I'm trying to process a unix-formatted flat file. The flat file uses line feed characters to delimit fields, and form feed characters to delimit a record. I am trying to convert the FF to anything else (CRLF, ';', TAB, etc). I have tried using the following perl one-liners with no success:
perl -p -e 's/\f/\r\n/g' < unix.txt > dos.txt
perl -p -e 's/\x0c/\x0d\x0a/g' < unix.txt > dos.txt
perl -p -e 's/\f/\t/g' < unix.txt > dos.txt
The only thing I've noticed is that the the dos.txt ends up with all the LF chars converted to CRLF, but the FF chars remain. I've even tried to reprocess the dos.txt file, again trying to replace the FF, but still no dice. I am still very much a perl newbie, so maybe I'm missing something? Does anyone know why the above commands don't do what I want them to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 Windows shell 不像 Unix shell 那样解释单引号。您应该在命令中使用双引号。
The problem is that the Windows shell doesn't interpret single quotes the way the Unix shell does. You should use double quotes in your commands.
你想要 bin 模式:
You want binmode: