기본 콘텐츠로 건너뛰기

simple susst using regular expresion

#!/usr/local/bin/perl -w

use strict;

local *FH1;
local *FH2;
my $source;
my $target;

foreach $source (@ARGV) {
$target = "converted_" . $source;
open(FH1, "<", $source) || die "Open $source was failed.\n";
open(FH2, ">", $target) || die "Create $target was failed.\n";

while () {
$_ =~ s/^,[^"]*(?=\n)$/$&"/;
print(FH2 $_);
}

close(FH1) || die "Close $source was failed.\n";
close(FH2) || die "Close $target was failed.\n";
}

exit 0;

댓글

SilverBullet님의 메시지…
더욱더 간단하게 하는 방법

perl -p -e "s/^,(.+?)([^\"])$/,\1\2\"/g" test.dat

windows 환경에서는 "표를 사용해야함