Strawberry Perl为什么不删除这些换页符? [英] Why won't Strawberry Perl remove these form feed characters?

查看:157
本文介绍了Strawberry Perl为什么不删除这些换页符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在WinXP上运行Strawberry Perl,并且正在尝试处理Unix格式的平面文件.平面文件使用换行符来分隔字段,并使用换行符来分隔记录.我正在尝试将FF转换为其他任何格式(CRLF,;",TAB等).我尝试使用以下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

我唯一注意到的是dos.txt最终将所有LF字符转换为CRLF,但保留了FF字符.我什至尝试重新处理dos.txt文件,再次尝试替换FF,但仍然没有骰子.我仍然是一个perl新手,所以也许我想念一些东西吗?有谁知道上面的命令为什么不执行我希望他们执行的操作?

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?

推荐答案

问题是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.

C:\ perl -e "print qq/foo\fbar/" > test.txt
C:\ type test.txt
foo♀bar
C:\ perl -pe 's/\f/__FF__/' < test.txt
foo♀bar
C:\ perl -pe "s/\f/__FF__/" < test.txt
foo__FF__bar

这篇关于Strawberry Perl为什么不删除这些换页符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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