Kod: Zaznacz cały
awk 'BEGIN { FS = "," } ; { print $0 "," $3 }' plik.csv
Kod: Zaznacz cały
awk 'BEGIN { FS = "," } ; { print $0 "," $3 }' plik.csv
Kod: Zaznacz cały
#!/usr/bin/perl
print "Usage: perl.pl input_filename [output_filename] [column_index] [additional_column_index]\n";
print "Working...\n";
$ifile = $ARGV[0];
$ofile = $ARGV[1];
$column = $ARGV[2];
$column2 = $ARGV[3];
open(FILE, "<", $ifile.".csv") or die $!;
if ($ofile ne "") {
open(OUTPUT, ">", $ofile.".csv") or die $!;
open(OUTPUT2, ">", $ofile."_rel.csv") or die $!;
open(HEADER1, "<", $ofile.".txt") or die $!;
open(HEADER2, "<", $ofile."_rel.txt") or die $!;
print OUTPUT2 <HEADER2>;
} else {
open(OUTPUT, ">", "_".$ifile.".csv") or die $!;
open(HEADER1, "<", $ifile.".txt") or die $!;
}
print OUTPUT <HEADER1>;
while (<FILE>) {
chomp;
#Replace , with #v#
$_ =~ s/,/#v#/g;
#Replace § with ,
$_ =~ s/§/,/g;
#Remove last column
$_ =~ s/,\w*$//g;
$line_to_save = $_;
if ($ofile ne "") {
@line = split(/,/, $_);
$var = @line[$column];
$var2 = @line[$column2];
$tail = $var;
$tail =~ s/^.+\_.+\_.+\_//g;
#print $tail."\n";
$head = $var;
$head =~ s/\d\_.{4}$//g;
#print $head."\n";
$line_to_save = $line_to_save.",".$head.$tail;
if ($column2 eq "") {
print OUTPUT2 $var.",".$head.$tail."\n";
} else {
print OUTPUT2 $var.",".$head.$tail.",".$var2."\n";
}
}
print OUTPUT $line_to_save."\n";
}
close(FILE);
close(HEADER1);
close(HEADER2);
close(OUTPUT);
close(OUTPUT2);
print "Done.\n";
Kod: Zaznacz cały
real 0m5.640s
user 0m5.080s
sys 0m0.404s