Threaded | Oldest First Previous Topic | Next Topic | Bottom
Stefan
Posted on: 8/16/2012 1:49 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 285
Re: Macro: Paste/Merge/Join two list together side-by-side
Merge two list together side-by-side RANDOM-ized

Hi folks, I was asked how to
random the two list together side-by-side.

``````
//EmEditor Script (JavaScript)
// Merge two list together side-by-side RANDOM-ized
// shuffle intermix stochastic stochastically
// (see examples) Writes result to new document.

//=======================================================
//============ U S E R S E T T I N G S ==================

// Separate your two input list by at least 5 #'s
// Example input:
//  JAMES
//  JOHN   <<< Left side in output
//  WILLIAM
//  RICHARD
//  CHARLES
//  ##########  <<< Five or more #'s, but not less!
//  MARY
//  PATRICIA
//  LINDA  <<< Right side in output
//  BARBARA
//  ELIZABETH
Separator = "#####";

// Delimiter to be used for separating
// consecutive values on a single line.
// Join both input lists side-by-side,
// Example output:
//  WILLIAM + ELIZABETH
//  CHARLES + PATRICIA
//  RICHARD + BARBARA
//  JAMES + MARY
//  JOHN + LINDA
//  or
//  JOHN + BARBARA
//  JAMES + PATRICIA
//  RICHARD + ELIZABETH
//  CHARLES + LINDA
//  WILLIAM + MARY
//  or
//  WILLIAM + PATRICIA
//  JAMES + BARBARA
//  RICHARD + ELIZABETH
//  CHARLES + LINDA
//  JOHN + MARY
//  or...
//
Delimeter = " + ";

//===========================================================
//===========================================================
//============ T H E   S C R I P T ==========================

document.selection.SelectAll();
Lines = sel.split("\r\n");     //Using Windows Line Enders here
SeparatorFound = false;
arrONE = new Array();
arrTWO = new Array();
arrOUT = new Array();

for(L = 0, Ls = Lines.length; L < Ls; L++){
if (Lines[L].indexOf(Separator) != -1){
SeparatorFound = true; continue; //SKIP
}
if (SeparatorFound==false){
arrONE[L] = Lines[L];
}else{
arrTWO[L] = Lines[L];
}
}

//Randomize the order of the array:
arrONE.sort( function() {return 0.5 - Math.random()} );
arrTWO.sort( function() {return 0.5 - Math.random()} );
//Join the arrays side-by-side:
for(idx=0,Len=arrONE.length; idx<Len; idx++){
arrOUT[idx] = arrONE[idx] + Delimeter + arrTWO[idx];
}
//============ O U T P U T =================================
OUT = arrOUT.join("\r\n");

//Works with EmEditor:
editor.NewFile();
document.write(OUT);

//The End
//===========================================================
``````

shuffle intermix stochastic stochastically random randomized
Stefan
Posted on: 8/15/2012 7:24 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 285
Macro: Paste/Merge/Join two list together side-by-side
I just had again the need to put to directory listings
together side by side for to use with e.g. renamer BRU.

Something like:

LEFT:
D:\Path\file01.ext
D:\Path\file02.ext
D:\Path\file03.ext
RIGHT:
D:\Path\new name01.ion
D:\Path\new name02.ion
D:\Path\new name03.ion
BECOMES joined (for "Renaming From A Text File" for BRU):
D:\Path\file01.ext|D:\Path\new name01.ion
D:\Path\file02.ext|D:\Path\new name02.ion
D:\Path\file03.ext|D:\Path\new name03.ion

Therefor i wrote an script i wanted to for longer.

How to use:
- Open an new document.
- Paste the first list in.
- Add underneath an empty line and write 5 #'s
- Paste the second list beneath.
-
- BE SURE to have no empty lines!
- And best have same amount of lines in both list.
-
- Change Separator and Delimiter in script if needed.
-
- Execute this macro, the joined output
will be pasted into an new document.

Example use:

INPUT document (##### as separator):
D:\Path\file01.ext
D:\Path\file02.ext
D:\Path\file03.ext
##### < remember: at least 5 #'s
D:\Path\new name01.ion
D:\Path\new name02.ion
D:\Path\new name03.ion

OUTPUT document (Pipe | as delimiter):
D:\Path\file01.ext|D:\Path\new name01.ion
D:\Path\file02.ext|D:\Path\new name02.ion
D:\Path\file03.ext|D:\Path\new name03.ion

Here is the script:
``````
//EmEditor Script (JavaScript)
// Paste/Merge/Join two list together side-by-side.
// (see examples) Writes result to new document.
//
// Works like one feature of PASTE.exe
//  paste is a Unix command line utility which
//  is used to join files horizontally (parallel merging)
//  by outputting lines consisting of the sequentially
//  corresponding lines of each file specified, [...]
//  It is effectively the horizontal equivalent to the
//  utility cat command which operates on the vertical
//  plane of two or more files.
//=======================================================

//    How to use:
//    - Open an new document.
//    - Paste the first list in.
//    - Add underneath an empty line and write 5 #'s
//    - Paste the second list beneath.
//    -
//    - BE SURE to have no empty lines!
//    - And best have same amount of lines in both list.
//    -
//    - Change Separator and Delimiter in script if needed.
//    -
//    - Execute this macro, the joined output
//      will be pasted into an new document.

//=======================================================
//============ U S E R S E T T I N G S ==================

// Separate your two input list by at least 5 #'s
// Example input:
// 	Eins
// 	Zwei   <<< Left side in output
// 	Drei
// 	Vier
// 	#####  <<< Five or more #'s, but not less!
// 	One
// 	Two
// 	Three  <<< Right side in output
// 	Four
//
Separator = "#####";

// Delimiter to be used for separating
// consecutive values on a single line.
// Join both input lists side-by-side,
// Example output:
// 	Eins|One
// 	Zwei|Two
// 	Drei|Three
// 	Vier|Four
//
Delimeter = "|";

//===========================================================
//===========================================================
//============ T H E   S C R I P T ==========================

document.selection.SelectAll();
Lines = sel.split("\r\n");     //Using Windows Line Enders here
SeparatorFound = false;
aArr = new Array();
nCount=0;

for(L = 0, Ls = Lines.length; L < Ls; L++){
if (Lines[L].indexOf(Separator) != -1){
SeparatorFound = true; continue; //SKIP
}
if (SeparatorFound==false){
aArr[L] = Lines[L]; nCount++;
}else{
aArr[L -nCount -1] +=  Delimeter + Lines[L];
}
}

//============ O U T P U T =================================
OUT = aArr.join("\r\n");

//Works with EmEditor:
editor.NewFile();
document.write(OUT);

//The End
//===========================================================
``````
 Threaded | Oldest First Previous Topic | Next Topic | Top

 Register To Post ________________Announcements  - Announcements ________________EmEditor Core  - Questions and Answers about EmEditor Core   - Regular Expressions   - EmEditor Core Enhancement Suggestions   - EmEditor Core Bug Reports ________________Plug-ins  - Questions and Answers about Plug-ins   - Enhancement Suggestions about Plug-ins   - Plug-in Bug Reports ________________Macros  - Questions and Answers about Macros   - Enhancement Suggestions about Macros   - Macro Samples ________________Beta Room  - Beta Version Bug Reports ________________User Comments  - Testimonials ________________Other Topics  - Other Programs   - General