C
L
O
S
E
8
|
2005-11-18-14-51 start
Please exam the output carefully. For example
next is one line of input
column 1;column 2 ; column 3 ; column 4 ; col 5 ; col 6 ; col 7
column 1;column 2 ; col 5 ; col 6 ; col 7; column 4 ; column 3
above is one line of output
Data actually has seven columns. But user specify
Data separator string: ;
How many columns/line: 5 (inaccurate data)
Left column for Exchange: 3
Right column for Exchange: 5
Program did right job and output is a surprise.
User assigned 5 column per line, so
[col 5 ; col 6 ; col 7] all together is one
column (column 5) This combined column 5 exchange
with column 3 get above output line.
2005-11-18-14-56 stop
2005-11-11-20-38 start
Use tab ('\t') as key string, or
use blank (' ') as key string, or
use white as key string, what is the difference?
White include both blank ' ' and tab '\t'.
Most application use tab as column separator, allow ' '
be used in specification description words. But in some
case, a data file may not use tab as column separator.
In this case http://freeman2.com/jslxrxv2.htm can help.
jslxrxv2.htm allow variable ' ' and variable white as data
column separator. User can specify
either one ' ' to many ' ' as separator,
or two ' ' to many ' ' as separator.
one ' ' to many ' ' not allow ' ' be used in specification
description words
two ' ' to many ' ' do allow ' ' be used in specification
description words.
If user choose white as key string, all tab change to ' ',
but still preserve tab in output.
Program allow fixed white as data separator. For example
use two blank " " as separator. In this case if input has
six blank " " string, this string has three separator.
If user forget six blank string has three two-blank separator
then cause puzzle.
2005-11-11-21-00 stop
2005-11-11-11-10 start
This program is designed to exchange any two data
columns. BUT if you want to move old column 6 to
new column 1 and shift old column 1 ... old column 5
to right one place. This program lack of this function.
If input data is vertically align in column, use
Byte Location method to exchange two sections.
Section 1 is col 1 to col 5, section 2 is column 6
On the other hand, if input data is NOT vertically
align in column, only way to do this job is
exchange column 5 and column 6, then click "R2:Box2->1;Box1->2"
exchange column 4 and column 5, then click "R2:Box2->1;Box1->2"
.....
exchange column 1 and column 2.
2005-11-11-11-27 stop
2005-11-11-20-08 start
This program supply debug information. But to print debug
data slow down process range from 100 to 600 times. Program
default not to print debug data. If user click check box
[Print debug to box 4 (SLOW DOWN !! try small file<10k)]
then print debug data. Key string used in exchange column
and in split file left/right. Key string table printed as
the following
sepLocArray 2090,2104,2121,2137,2141,2148 AZG
sepLenArray 5, 8, 8, 1, 1, 1 AZG
above small input data, table align well.
below big input data, table align fail.
sepLocArray 27152,27166,27183,27199,27204,27211 AZG
sepLenArray 5, 8, 8, 2, 1, 1 AZG
Here key string length varies, because here use variable
white space as key string. Test program on purpose.
Debug code check box suggest "try small file<10k"
10k (10000) and up, program unable to care and align fail.
Number in sepLocArray is key string absolute location in
input file. It can be as large as input file total size.
Number in sepLenArray is key string length, input file size
has nothing to do with key string length. sepLenArray value
is one digit number in most case.
sepLocArray means SEParation string LOCation ARRAY
sepLenArray means SEParation string LENgth ARRAY
Table alignment code in exchange column jobs.
Table alignment NOT code in split file job.
Merge file no need key string, no table.
2005-11-11-20-29 stop
2005-11-13-11-13 start
This program has one reserved string, it is
"\AEoBGYTcTHVz"
All occurrence are changed to '\'.
Why use reserved string?
When merge two files left/right to one file, program
allow user to insert
Head (left) string
Middle string
tail (right) string
After merge, output line look like following
[headStr]LeftFileLineNumber3[MiddleStr]RightFileLineNumber3[TailStr]
[headStr] and [MiddleStr] and [TailStr] are optional
(general name is "insert string")
if they are not defined by user, then output is simply
LeftFileLineNumber1RightFileLineNumber1
LeftFileLineNumber2RightFileLineNumber2
LeftFileLineNumber3RightFileLineNumber3
.....
[headStr] and [MiddleStr] and [TailStr] can be any
text, include tab [\t] and newline [\n] (change line)
User can not put newline directly into insert string.
Program support three escape bytes, they are
\t for tab
\n for newline
\\ for '\'
If user define [headStr] to be "\n\n", then two
newline will inserted at beginning of merged line.
But '\t' and \n' and '\\' are representation only
'\t' is not real tab
'\n' is not real newline
'\\' is not real '\'
Program replace these escape bytes with real bytes.
Replacement has necessary order. If wrong order, get
unexpected result. For example, if user input "\\n"
If replace '\n' first (mistake) then "\\n" become
"\ture-new-line" that is next two lines
"\
"
We can not printout '\n' as user expected.
First replace '\\' with real '\' (if there is any)
Second replace '\n' with real newline (if there is any)
Third replace '\t' with real tab (if there is any)
If user want program print out a newline, he use '\n'
If user want program print out a newline escape
expression, he use '\\n'
Ths string '\\n' only '\\' is escaped, after replace
'\\n' become '\n' for print out. Program will not do
second replacement, '\n' will not change to real new
line.
2005-11-13-11-36 stop
2005-11-13-12-55 start
Although "'\n' will not change to real new line."
when come to step two, change '\n' to real newline.
How can we tell
this '\n' is never be replaced? (should change to
real newline) or
this '\n' is replaced from '\\n'? (should avoid)
This program use reserved string "\AEoBGYTcTHVz" to
solve this problem.
all '\\' replace to '\AEoBGYTcTHVz'
"\\n" become "\AEoBGYTcTHVzn"
after done '\n' and '\t' replacement
change '\AEoBGYTcTHVz' to '\' then
"\AEoBGYTcTHVzn" become "\n" for printout.
replacement from '\AEoBGYTcTHVz' to '\'
only occurs in
Head (left) string definition
Middle string definition
tail (right) string definition
replacement from '\AEoBGYTcTHVz' to '\'
NOT occur in input left/right files.
2005-11-13-13-23 stop
2005-11-15-21-38 start
below is a sample debug output
First line is a comment line. Comment is defined at
Comment line string [%%] Nothing for no comment line.
User fill in "%%" to active comment line function.
Comment line no column exchange.
Comment line sepLocArray and sepLenArray undefined
Comment line use "////////////"
0000000000111111111122222222223333333333 <= omitted
01234567890123456789012345678901234567890123 "`" = tab
%% This line is comment line, no column exchange
////////////////////////////////////////////////
sepLocArray
sepLenArray
=====
Second line is a data line
4444555555555566666666667777777777888888 <= omitted
6789012345678901234567890123456789012345678901234567890123456789 "`" = tab
column 1 column 2 ` column 3 `column 4 col 5 `col 6` col 7
--------##--------###--------###--------####-----###-----##-----
sepLocArray 54, 64, 75, 86, 95, 103 AZG
sepLenArray 2, 3, 3, 4, 3, 2 AZG
This is a variable white string sample.
"White" include blank ' ' and tab, in key string
determination process, tab changed to ' ' to simplify
search action.
'`' represent tab (not print actual tab) allow '#'
align vertically with data line.
"##" or "###" or "####" are where key string located.
This example run with "Two white to many white."
checked. TWO or more white bytes are separator.
One white ' ' in "column 1" is not a separator.
Number above "column 1 column 2 ..... " is
byte location number single digit part. Here
added byte location number ten's digit part
for convenience.
Byte location number and length should match
sepLocArray and sepLenArray perfectly.
2005-11-15-21-59 stop
##### Above program usage
##### Below history, efficiency etc
2005-10-18-16-22
On 2000-01-02-14-42 Freeman's brother called for help.
Asked to modify data from "01/02/00" to "01/02/2000".
2000-01-08-23-20 get the idea what if not insert, but
write left side to one output file and write right
side to another output file? If do so, then I split
one file into left and right two files. Freeman wrote
DOS application to split/merge file.
On 2005-10-02 Freeman start write JavaScript version
data COLUMN exchange, split file left/right and merge
file left/right. 2005-10-18 finish JavaScript version.
This program http://freeman2.com/jslxrxv2.htm
1. Exchange two data columns.
2. Split one file into left and right two output files
3. Merge two files side by side into one file.
Exchange two data columns must define separator first.
It has following choices
1. User assign byte location. Very often it is called
(byte) column number, but this program use "column"
for data field, and avoid use (byte) column number,
use byte location instead.
2. Key string to separate columns. Key string can be
any string (but NOT newline) Example: ';' or "(#)".
3. Tab to separate columns. Tab is used in spread sheet
to separate columns. One tab is one separator.
4. Space ' ' separate columns. It can be fixed length
space or variable length space.
Variable length space separator has two choices
a: one ' ' to many ' ' (continuously),
not allow ' ' in specification field.
b: two ' ' to many ' ' (continuously)
allow one ' ' in specification field.
5. White string separate columns. White string include
blank ' ' and tab.
If you put string into "Comment line string" box, all
line begin with you specified string will NOT exchange
column. Program treat this line as comment line.
Split one file into two left/right files need to find
cutting point first. To identify cutting point is same
as to identify column separator above.
To merge two files, it can be done directly. This
program allow you to specify head string, middle string
and tail string.
If you use "\n\n\n" as head string, output will
separate lines by two blank lines.
If you use "\n" as middle string, output look like
shuffled playing cards.
If you use "#KEY#" as middle string, later you can
use "#KEY#" as key string and cut file again.
Most important about JavaScript program is its speed.
JavaScript language, like DOS batch file language, is
interpreter, not translator. Interpreter do the
job on fly, computer read JavaScript code then carry
out the command line by line. All interpreter
languages are slow. If it is a tiny job. Slow plus
tiny just few seconds, we do not feel waiting. But
slow plus small job, it takes more than 10 seconds.
User start wondering what is going on. This program
http://freeman2.com/jslxrxv2.htm
is right for tiny job, it is slow for small job,
too slow for medium job. Impossible for big job.
2005-10-18-17-43 stop
2005-11-11-22-10 start
This program is partial efficient.
At first shift whole input forward. Move done-line out
of sight. Move next line to new line 1. But to shift
whole input file many times that is low efficient !
Start from 2005-10-19 re-write whole program. Keep
input file unchanged. Move all pointer from beginning
of file to end of file. This change should save time.
Not efficient part is that repeat code appear several
places. For example "Two ' ' to many ' '" check box
show up in four places. It can be done in one place
and serve all needs.
The code "Done, elapse: ..... sec ....." also repeat.
This code can change to function and simplify code.
Freeman declare that he is programming admirer, not
an expert, not even a 5% expert. Just write very few
and short and simple text-management applications.
I hope to improve in the future.
2005-11-11-22-22 stop
2005-11-12-11-07 start
Freeman use Pentium 4, HP pavilion a255c computer
Operating system Windows XP, service pack 2
Browser is MSIE 6.0.2900.....
First test run with input 23323 bytes and 201 lines
done in 0.484 sec, no debug code
done in 293 sec, HAS debug code Debug code access
external document.form0.box01.value heavily.
Regular code use internal variables.
293/.484 = 605 times longer
2005-11-12 morning change all code (include debug code)
read/write web page box just once. All calculation are
done with internal variables. Debug time reduce
from 600-times to 100-times
Second test run with input 46611 bytes and 401 lines
elapse 0.111 sec not request debug
elapse 10.7 sec did request debug
(regular and debug code all internal variable)
10.7/0.111 = 96 times
96-times is much better than 600-times.
2005-11-12-11-27 stop
2005-11-18-15-11 start
This program gradually improve. Above mentioned
elapse time relative magnitude my be out of date.
The program code numbering
first use *EX001*, after add/remove code
second use *XC001*, for eXchange Column
third use *XD001*,
fourth use *XE001*,
fifth use *XF001* (next change)
I just find that somewhere still mention *EX504*
(I change to *XE564* then *XF567*)
In case these old number show up somewhere,
reader should know it is ignored old notes.
2005-11-18-15-17 stop
2005-12-18-16-11 start
Above has
[[
2005-11-11-11-10 start
This program is designed to exchange any two data
columns. BUT if you want to move old column 6 to
new column 1 and shift old column 1 ... old column 5
to right one place. This program lack of this function.
]]
There is a third method. Split then merge.
Assume input data has seven columns.
Assume want to move column 5 and 6 to column 1 and 2.
Key point for third method is that
Input file both end no column separator string.
Output file both end no column separator string.
Left to first data no need separator string.
Right to last data no need separator string.
Do third method as following:
Use jslxrxv2.htm to split input file into THREE
output files.
LEFT out contains column 1 to column 4
MIDDLE out contains column 5 and column 6
RIGHT out contains column 7
(Three stripe split/merge file)
Split: LEFT, MIDDLE, RIGHT (RIGHT file no change)
Merge: MIDDLE, LEFT, RIGHT (RIGHT file no change)
If three stripe split/merge file involve
LEFT, MIDDLE exchange, (RIGHT file no change)
separator string put at left output right end
After LEFT, MIDDLE exchange, MIDDLE become new
left, and its left side no separator string.
If three stripe split/merge file involve
MIDDLE, RIGHT exchange, (LEFT file no change)
separator string put at right output left end
After MIDDLE, RIGHT exchange, MIDDLE become new
right, and its right side no separator string.
If three stripe split/merge file involve
LEFT, RIGHT exchange, (MIDDLE file no change)
separator string put at MIDDLE output ends.
After LEFT, RIGHT exchange, output both side
no separator string.
First split input file to
LEFT&MIDDLE file and RIGHT file, in
"Key string location" box fill 'L' to put
separator string to LEFT&MIDDLE file.
Second split LEFT&MIDDLE file to
LEFT file and MIDDLE file. in
"Key string location" box fill 'R' to put
separator string to MIDDLE file.
Now MIDDLE file both end has separator string.
LEFT file and RIGHT file both end NO separator
string. After merge to new order, output both
end no separator string.
If output either end has separator string, that
is a signal of error, because somewhere in middle
loss separator string.
2005-12-18-16-31 stop
|