我有一个文件,其中包含每小时12,000
生成的 aprox 行6
。在其中一些行中,有非 ascii 字符。
我希望能够运行 Perl 脚本来删除其中包含非 ASCII 字符的所有行。
我有一个文件,其中包含每小时12,000
生成的 aprox 行6
。在其中一些行中,有非 ascii 字符。
我希望能够运行 Perl 脚本来删除其中包含非 ASCII 字符的所有行。
你可以做:
perl -i.bak -ne 'print unless(/[^[:ascii:]]/)' file
正则表达式解释/[^[:ascii:]]/
:
/
正则表达式
[
的开头 字符类的开头
^
使其成为负字符类(匹配除所列内容之外的任何内容的类)
[:ascii:]
任何 ASCII 字符
]
字符类
/
的结尾 正则表达式的结尾
#!/usr/bin/perl -p
END {close STDOUT}
use 5.010;
use utf8;
use strict;
use autodie;
use warnings qw<FATAL all>;
use open qw<IN :bytes OUT :encoding(US-ASCII) :std>;
BEGIN {$SIG{__WARN__}=sub{confess}}
use sigtrap qw<stack-trace normal-signals error-signals>;
use Carp;
"disconcertingly";