Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #/media/yiguanas/Sam3/ubuntuSW/MT4/tester/history/AJnicify.pl
- #INPUT:
- #USDJPY.txt: (is the original, SORTED file as extracted from the zip archive)
- #<TICKER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>
- #USDJPY,20010102,230300,114.43,114.43,114.43,114.43,4
- #USDJPY,20010102,230400,114.44,114.44,114.44,114.44,4
- #USDJPY,20010102,230500,114.44,114.44,114.44,114.44,4
- #OUTPUT format: remove header, symbol and comma; add hyphens and colon; remove 00
- #2001-11-09,20:19,120.29,120.30,120.29,120.30,4
- #2001-11-09,20:20,120.30,120.30,120.30,120.30,4
- #2001-11-09,20:21,120.30,120.31,120.30,120.31,4
- #2001-11-09,20:22,120.31,120.31,120.31,120.31,4
- #2001-11-09,20:23,120.31,120.31,120.30,120.30,4
- #TO EXECUTE THIS PROGRAM:
- # $ cat ./USDJPY.txt | perl ./AJnicify.pl > xxx.txt #OR:
- # $ cat ./USDJPY.txt | perl ./AJnicify.pl 20011109,2019 20011109,2022
- #2001-11-09,20:20,120.30,120.30,120.30,120.30,4
- #2001-11-09,20:21,120.30,120.31,120.30,120.31,4
- #2001-11-09,20:22,120.31,120.31,120.31,120.31,4
- #XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- sub no_args_sub {
- <>; #first line (=unwanted header) gets lost intentionally
- while ( defined($_ = <>) ) #reads from stdin (& theoretically also command line args)
- {
- # s/USDJPY,//; #works
- s/([A-Z].....,)(.*)/2/; #remove first 6 capital letters
- s/([0-9]...)([0-9].)([0-9].),([0-9].)([0-9].)([0-9].)/1-2-3,4:5/;
- print $_;
- } #while
- } #sub no_args_sub
- #XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- sub two_args_sub {
- open STDERR, '>/dev/null'; #naughty!
- #my distinction of stdin / command line args isn't perfect. Want to avoid error msgs:
- #Can't open 20011109,2019: No such file or directory at ./AJnicify.pl line 69.
- #Can't open 20011109,2022: No such file or directory at ./AJnicify.pl line 69.
- if (!($firstarg le $secondarg)) {
- die "1st arg must be < 2nd arg and of form 20010102,2346n";
- }
- <>; #get command line out of the way of the stream
- <>; #first line (=unwanted header) gets lost intentionally
- my $continue = 1;
- do # I use DO UNTIL instead of usual WHILE to get that extra match at the start
- {
- s/.{6},//; #works
- s/d+,d+(?=.*)/$&/;
- if ($& ge $firstarg) { $continue = 0; }
- } until (($continue == 0) || (!defined($_ = <>)));
- $continue = 1;
- while ( (defined($_ = <>)) && ($continue == 1) )
- #: reads from stdin (& theoretically also command line args)
- {
- my $tmp = $_;
- $tmp =~ s/d+,d+(?=.*)/$&/;
- if ($& gt $secondarg) { $continue = 0; }
- s/([A-Z].....,)(.*)/2/; #remove first 6 capital letters
- s/([0-9]...)([0-9].)([0-9].),([0-9].)([0-9].)([0-9].)/1-2-3,4:5/;
- print $_;
- } # while
- close STDERR;
- } # two_args_sub
- #XXXXXXXXXXXXXXXXXXXXXXX "MAIN" XXXXXXXXXXXXXXXXXXXXXXX
- my $CL_len = $#ARGV + 1; #GLOBAL VARS; must do this BEFORE <>
- $firstarg = $ARGV[0]; #print "firstarg=$firstargn";
- $secondarg = $ARGV[1]; #print "secondarg=$secondargn";
- if ($CL_len == 2) { two_args_sub; }
- elsif ($CL_len == 0) { no_args_sub; }
- else {
- die "I quit - I needed no args or 2 args of form: 20010102,2346 (=2nd Jan 2001,23:46)n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement