use strict; use warnings; use Text::CSV; my( $infile, $outfile, @cols ) = @ARGV; print "Reading from $infile.\n"; print "Writing to $outfile.\n"; print "Target columns are @cols.\n"; open my $in, "<", $infile or die "Cannot open $infile: $!\n"; open my $out, ">", $outfile or die "Cannot open $outfile: $!\n"; $_-- for @cols; # correct column numbering my $csv = Text::CSV->new( ); my $pipe = Text::CSV->new( { sep_char => '|' } ); my $tilde = Text::CSV->new( { sep_char => '~', eol => "\n" } ); while( my $line = $csv->getline( $in ) ) { $pipe ->combine( @$line ); $tilde->combine( @$line[@cols], $pipe->string ); print $out $tilde->string; } close $out; close $in;