Try this (untested):
tr -d "\"" < input > output
سؤال
I want to remove all double quotes from my csv file, and am struggling to get tr, sed, or perl to work for me and output to file:
perl -e 's/\"//g;" input.csv > output.csv
gives no output to screen or file, with output.csv not created
sed 's/\"//g' input.csv > output.csv
prints output to the screen, and then gives errors "can't read >: No such file or directory" "can't read output.csv: No such file or directory"
cat input.csv | tr -d '\"' > output.csv
gives error "tr: extra operand '>'", then error "write error: No space left on device"
What am I doing wrong?
المحلول 2
Try this (untested):
tr -d "\"" < input > output
نصائح أخرى
To get your perl version to work, you just need the -p
option to indicate printing to the screen:
perl -pe 's/"//g' input.csv > output.csv
Or if you're on windows, do the following:
perl -pe "s/\x22//g" input.csv > output.csv
Also, instead of blindly removing double quotes from a csv, I'd recommend using an actual csv parser to selectively remove double quotes only from those fields where it isn't needed. The following script could do that:
use strict;
use warnings;
use Text::CSV;
my $csv = Text::CSV->new ( { binary => 1, eol => "\n" } )
or die "Cannot use CSV: ".Text::CSV->error_diag();
if (@ARGV != 1) {
print "usage: $0 [csvfile]\n";
exit;
}
while (<>) {
$csv->parse($_);
$csv->combine( $csv->fields() );
print $csv->string();
}