脚本(最初从这里复制)将一个固定宽度的文本文件作为输入,重新排列列的顺序,并且应该输出一个固定宽度的文本文件。但是尾随空格被从变量中截断,这意味着输出不是固定宽度的。
open(INPUT, "</home/ecom/tmp/citiBIG/GROUP.txt");
open(OUTPUT, ">/home/ecom/tmp/citiBIG/GROUP2.txt");
my $LINEFORMAT = "A2 A7 A14 A4 A2 A2 A4 A12 A25 A30 A26 A40 A40 A40 A25 A4 A12 A14 A2 A8 A12 A70 A8"; # Adjust to your
field widths
while(<INPUT>) {
chomp;
my($Null0, $EmpNum, $CcNumber, $Null1, $CcExpYy, $CcExpMm, $Null2, $Title, $LastName, $FirstName, $HolderName, $Ad
dress1, $Address2, $Address3, $Suburb, $State, $PostCode, $Null3, $AreaCode, $WorkPhone, $Null4, $Email, $GroupName) =
unpack($LINEFORMAT, $_);
print OUTPUT $EmpNum . " " . "~" . $LastName . "~" . $FirstName . "~" . $Title . " " . "~" .
$Address1 . "~" . $Address2 . "~" . $Address3 . "~" . $Suburb . "~" . $PostCode . "~" . $State . "~" . $AreaCode . "~"
. $WorkPhone . "~" . $CcNumber . "~" . $CcExpMm . "~" . $CcExpYy . "~" . $HolderName . "~" . $Email . "~" . $GroupNam
e . " " . "~" . "\n";
}
close INPUT;
close OUTPUT;