In a message dated: Wed, 16 Feb 2000 13:59:35 EST
Charles Farinella said:

>I am happy to have whatever help I can get.  Thanks.
>
>This kind of works.  I didn't explain well.
>
>The file I have is set up as such:
>
>id,mm/dd/yy/,text,$00.00


Charlie, if this data format is accurate, then here's a small perl script that
you can run to convert your various files.  I'm assuming this may not be just 
a one time thing, and that you may need to do this again in the future.

The one-liners I saw looked good, but confusing if you don't know what's going 
on in sed or perl.  This perl script is commented, and I tried to stay away 
from any perl "magic" :)  Just cut'n' paste this code into a file, save it,
name it whatever you want, and chmod 755 (or whatever) it.


Hope this helps!

Seeya,
Paul

#!/usr/local/bin/perl

use Getopt::Std;                # use the Getopt::Std module for 

getopts('i:o:h');               # use options -i,-o, and -h
                                # -i and -o both take file name arguments

if (!(($opt_i) or ($opt_o)) or ($opt_h)) {
  #If -i and -o aren't both specified, or -h is specified
  #print a Usage statement

  print STDERR "Usage: $0 -i <infile> -o <outfile>\n\n";
  print STDERR "Use of '-' for STDIN and STDOUT is allowed\n";

  # Note that you can use '-' to represent both STDIN and STDOUT for filenames
  # this allows things like "cat foo | convert -i - -o -" to just look at the
  # text on screen (of course you can just do "convert -i foo -o -" which
  # is much less typing :)
  die "\n";
}


# open the input file or die with an error
open (INFILE, "$opt_i") || die "Can't open file: $opt_i\n";


chomp(@infile=<INFILE>);        # read the file into an array
                                # and  remove trailing newlines

close (INFILE);                 # Close the file

# open the input file or die with an error
open (OUTFILE, ">$opt_o") || die "Can't open file: $opt_o\n";


foreach (@infile) {                             # for each line in the file
  ($id,$date,$text,$amount) = split(/,/);       # separate out the fields
  $date = join ('/', reverse ( split (/\//,$date)));    # pick apart the date
                                                        # reverse it
                                                        # put it back together
  $string = join (',',$id,$date,$text,$amount); # rejoin the whole string
  print OUTFILE ("$string\n");                  # write it out to the new file
}
close (OUTFILE);                # Close the file.



**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************

Reply via email to