이 명령을 사용하여 쉼표로 구분 된 파일을 탭으로 구분 된 파일로 변환하기 위해 perl을 사용하고 있습니다.
perl -e ' $sep=","; while(<>) { s/\Q$sep\E/\t/g; print $_; } warn "Changed $sep to tab on $. lines\n" ' csvfile.csv > tabfile.tab
그러나 내 파일에는 특정 열에서 분리하고 싶지 않은 추가 쉼표가 있습니다. 다음은 내 파일의 예입니다.
ADNP, "descript1, descript2", 1
PTB, "descriptA, descriptB", 5
따옴표 외부의 쉼표 만 탭으로 변환하고 싶습니다.
ADNP descript1, descript2 1
PTB descriptA, descriptB 5
어쨌든 perl, python 또는 bash로 이것을 할 수 있습니까?
Perl에서는 다음을 사용하여 간단합니다 Text::CSV
.
#!/usr/bin/env perl
use strict;
use warnings;
use Text::CSV;
#configure our read format using the default separator of ","
my $input_csv = Text::CSV->new( { binary => 1 } );
#configure our output format with a tab as separator.
my $output_csv = Text::CSV->new( { binary => 1, sep_char => "\t", eol => "\n" } );
#open input file
open my $input_fh, '<', "sample.csv" or die $!;
#iterate input file - reading in 'comma separated'
#printing out (to stdout -can use filehandle) tab separated.
while ( my $row = $input_csv->getline($input_fh) ) {
$output_csv->print( \*STDOUT, $row );
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다