#!/usr/bin/perl # $Id$ # # PERL script chopM: reads in ASCII text files (*.txt, *.csv, etc.) and removes # "^M" at end of each line. Ammended files are given extension ".new". # Original files are then deleted ("unlinked") and *.new files are renamed to # original input file names with orignal file extensions. # # Mary H L Anderberg # National Renewable Energy Laboratory # 13 May 1996 # # Open list file and read contents into array fnames unless (open(LIST, $ARGV[0])) { die ("Cannot open input file ARGV[0]\n"); } @fnames = ; #run through list of input filenames in array fnames $index = 0; while ($in = $fnames[$index]){ chop($in); # print ("Input filename is $in.\n"); #split extension off input filename, toss, save base @base = split(/\./,$in); $one[0] = $base[0]; $one[1] = "new"; $new = join (".",@one); # open input file unless (open(INFILE, $in)) { die ("Cannot open input file $fnames[$index]\n"); } unless (open(OUTFILE, ">$new")) { die ("Cannot open output file $new\n"); } while ($line = ) { chop ($line); chop ($line); print OUTFILE ($line); print OUTFILE ("\n"); } close (INFILE); close (OUTFILE); # remove original input file unlink ($in) || print "Cannot unlink $in !!!\n\n"; # rename output file to input filename rename ($new, $in) || print "Cannot rename $new to $in.\n\n"; # increment loop counter, read next input file name from list $index++; } print"\n\nFINISHED!!!\n\n";