SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Strategies & Market Trends : TA-Quotes Plus

 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext  
To: Paul Beattie who wrote (240)1/12/1997 5:43:00 PM
From: Paul Beattie   of 11149
 
Sort/Merge routine for QuotesPlus Lists:

I created the following script to combine lists of the kind used by QuotesPlus. It is written in the Perl Script language.

Perl is a language for easily manipulating text, files and processes. It is freely available over the internet and there are a number of good books available on it. Perl distribution is available from a number of sites. More information on Perl for Win32 at perl.hip.com . I'm not trying to convert anyone, but I find perl useful for automating text manipulation tasks.

I use this routine for:
1. comparing overlap between lists (ie. IBD YourWeekylReview and QP scan for QRS(0)>75)
2. generating a single sorted list from a routine set of nightly scans which I then pass to QP-Metastock output to move stock data into a directory for use by MSWIN. I do this as part of an automated process which "integrates" QP processing and provision of data to MSWIN.

I don't know if the SI thread will split any lines when I paste this text into the message. I expect simply cut and paste will be required to create the perl script file. Comment lines in perl begin with #.

I hope that this routine may be useful for others using QP and MSWIN.
Cheers,
Paul

----------------------------
Description of QP_SORT script:

The script must be executed from a command line (although this can be set up in a batch file, and a shortcut/icon created for it in Win95. See QP_SORT.BAT at end of this message).

It takes multiple list files as input, and prints one list file to STDOUT. Each output line is of the form <SYMBOL> <IN_LISTS>.
Input files can be specified on the command line. If none are specified, a set of default files is used. For instance, if there are 5 list files to combine, they are identified A-E. A legend summarizing the letters assigned to each file can be printed optionally.

Without the legend, if the output is redirected to a file, QuotesPlus can use it as a QP list. The QuotesPlus-MetaStock Output program can also use this list to transfer stock data in MSWIN format to directories of your choice.

Typical output would appear:

SYM1^^^^^^^^^^^^A.CD.^^^^^^^^^^^^These "^^^" are really spaces
SYM2^^^^^^^^^^^^.B.DE^^^^^^^^^^^^Doesn't show well with "normal font"
SYM3^^^^^^^^^^^^AB..E
SYM4^^^^^^^^^^^^....E

------------------Contents of sort_lst.pl-----------------
#!/usr/bin/perl
# sort_lst.pl Sort/Merge/Summarize List files
# of the format used by QuotesPlus
# - At this time, stock symbol is the first 6 chars in a line.
#
# Usage: perl sort_lst.pl [-x] [-l] [[file1] [file2] ...]
# -l to print Legend
# -x print usage information
# Other args are considered filenames, each
# containing a list of stock symbols
# in QuotesPlus format.
# (default files to use are defined below)
# Output is to STDOUT.
#
#

require "getopts.pl";

@default_files= ( # Routine uses these files if no arguments given
"C:\\QPLUSDAT\\LISTS\\BBB.LST",
"C:\\QPLUSDAT\\LISTS\\BIGDOG.LST",
"C:\\QPLUSDAT\\LISTS\\BREAKOUT.LST",
"C:\\QPLUSDAT\\LISTS\\HIGHFLY.LST",
"C:\\QPLUSDAT\\LISTS\\WATCHOUT.LST",
);

$PRINT_LEGEND = 0; # Flag: 0/1 to avoid/print file summary legend
# Will be set by use of -l option on command line.

#----------------------------------------------------------------
# Parse arguments and extract flags
&Getopts(':lx'); # -l and -x take no arguments
# Using them set opt_l, opt_x to 1 as a side effect

# -x flag used on command line
if ($opt_x == 1) {
print (STDERR "Usage: perl sort_lst.pl [-x] [-l] [-o Outputfile] [[file1] [file2] ...]\n");
print (STDERR "\t\t-l to print Legend\n");
print (STDERR "\t\t-o to specify file for Output (default is STDOUT)\n");
print (STDERR "\t\t-x print usage information only\n");
print (STDERR "\t\tOther args are considered filenames, each containing a list\n");
print (STDERR "\t\t of stock symbols in QuotesPlus format.\n\n");
exit;
}

#----------------------------------------------------------------
# check files named as input - all must be readable
$errflag=0;
foreach $i (0 .. $#ARGV) {
$filename=$ARGV[$i];
unless (-r $filename ){
printf (STDERR "Cannot read file: %s\n", $filename);
$errflag=1;
}
}
exit if ($errflag == 1);

#----------------------------------------------------------------
# If no files named on command line, use defaults
if ($#ARGV >= 0) {
@filenames = @ARGV;
}
else {
@filenames=@default_files;
}

$in_list_dots= "." x ($#filenames+1); # string repetition: "." for each file

# unique identifiers for 62 separate files
$charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

$PRINT_LEGEND = 1 if ($opt_l);

if ($PRINT_LEGEND) {
print ("Sort/Compare Symbols in Multiple Files\n");
print ("Legend - Letter mapping for files\n");
}

#----------------------------------------------------------------
# Process input files
$file_num = 0; # sequential number, starting at 0
foreach $filename (@filenames) {

# Open file for processing
unless (open(INPUT, $filename)) {
print STDERR "Can't open $filename: $!\n";
next;
}

$spec_char = substr($charset,$file_num,1); # char to specify file

if ($PRINT_LEGEND) {
printf (" %s: %s\n", $spec_char, $filename);
}
$in_list = $in_list_dots;
substr($in_list,$file_num,1) = $spec_char;

# process text in file.
# Read each paragraph and split into words. Record each
# instance of a word in the %symbolcount associative array.
while (<INPUT>) {
chomp; # remove trailing newline, if exists
# extract valid symbol from input line.
# symbol CAN contain blanks, but no more than 2
/^\s*([A-Z][A-Z0-9]{0,6} {0,2}[A-Z0-9]{0,4})/;

$symbol = sprintf("%-6.6s", $1); # fix length at 6 characters.
next if ($symbol =~ /^ *$/); # ignore blank lines
$symbol =~ tr/a-z/A-Z/; # Convert to uppercase.

if ($symbolcount{$symbol} eq "") {
$symbolcount{$symbol} = $in_list; # make entry
}
else {
$tmp = $symbolcount{$symbol};
substr($tmp,$file_num,1) = $spec_char;
$symbolcount{$symbol} = $tmp;
}
}
close(INPUT);
$file_num++;
}

# Print out all the entries in the %symbolcount array.

if ($PRINT_LEGEND) {
print "\n";
}

foreach $symbol (sort keys(%symbolcount)) {
printf ("%-10.10s %s\n", $symbol, $symbolcount{$symbol});
}

# ------------ end of sort_lst.pl

----------Contents of sort_lst.bat (MS-DOS batch file) ----

@perl sort_lst.pl > C:\QPLUSDAT\LISTS\combined.lst

------------------------------------------------------------
end of message
Report TOU ViolationShare This Post
 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext