Skip to content

Instantly share code, notes, and snippets.

@satojkovic
Created March 5, 2012 03:41
Show Gist options
  • Save satojkovic/1976414 to your computer and use it in GitHub Desktop.
Save satojkovic/1976414 to your computer and use it in GitHub Desktop.
Replace file extension txt to csv
#!perl
use strict;
use warnings;
use File::Basename;
use File::Spec;
use File::Copy;
my $file = shift;
if( !defined($file) ) { die "Usage : $0 <text file>"; }
my ($fn, $path, $ext) = fileparse($file, 'txt');
if( $ext ne 'txt' ) { die "$file is not text file..."; }
my $new_file = File::Spec->catfile($path, join("", $fn, "csv"));
if( copy $file, $new_file ) {
print "copy $new_file success!\n";
}
else {
print "copy $new_file failed...\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment