我想尝试打印 .txt 输入文件中的所有内容来处理一些数据,但我遇到了一些问题,因为打印出来的内容不符。我能知道为什么会这样吗?谢谢大家。我想生成内容并删除所有“0x”。
输入文件
0x30002; 0x0; 0x0
0x0; 0x0; 0x0
0x36460301; 0x15; 0x0
0x88A3; 0x0; 0x0
0xF0000D01; 0x4; 0x0
0xF0000D01; 0x5; 0x0
0xF0000501; 0x22882208; 0x0
0xF0000D0D; 0x7; 0x0
0xF0000D11; 0xD; 0x0
0xF0000D19; 0x2; 0x0
0xF0000105; 0x147; 0x0
0xF0000231; 0x8FC; 0x0
0xF0000909; 0x80327; 0x0
0xF000090D; 0xF4F3034A; 0x0
0xF0000911; 0xF5; 0x0
0xF0000E11; 0xA01FA00; 0x0
#!/bin/perl
#!/usr/local/ActivePerl-5.6/bin/perl -w
$infile = $ARGV[0];
$outfile = "$infile.dc";
$index = 0;
open (OUT, ">$outfile" );
$index = 0;
open (INF, "$infile") || die (" can not open input file \n" );
print "============After open infile=====================\n";
while(<INF>) {
if($_ =~ /$index/ )
{
chomp $_;
@temp2 = split (/\s+/,$_);
printf OUT (@temp2);
# printf OUT ("%-10s %7d %s %7.2f %s %7d %s \n",
# $temp2[5],$temp2[7], $temp2[8], $temp2[9], $temp2[10], $temp2[11], $temp2[12]);
}
if ($index < 2000) { $index = $index +1;}
else {$index = 2000;}
} # whole
# } # for
close (INF) || die "cannot close input file !!";
close (OUT);
#rename("$outfile1", "$infile.txt");
print " data is in $outfile. \n\n";
脚本的输出
0x30002;0x88A3;0xF0000D01;0xF0000D01;0xF0000D0D;0xF0000D19;0xF0000105;0x40109801;0xF3802001;0x480C7004;0xF0000010;0x54359026;
答案1
您想要实现的目标非常不明确。您应该通过清晰地解释您想要实现的目标、提供代码的最小示例(没有不必要的注释和不相关的代码)以及您提供的输入的预期输出来完成您的问题。如果只是0x
在文件中删除,那么这就足够了:
perl -wple's/0x//g' input.file