Difference between revisions of "Columns, Numbers"

From TED Notepad
 
Line 1: Line 1:
<noinclude>{{manversion|5.4.1.1}}__NOTOC__</noinclude>
+
<noinclude>{{manversion|6.0.0.16|feature}}__NOTOC__</noinclude>
 
====Columns, Numbers... (Alt+Ctrl+Y)====
 
====Columns, Numbers... (Alt+Ctrl+Y)====
  
Cuts portions from each {{defined|line}} and then gnerates new {{defined|lines}} according to the given {{field|Output mask}}. The mask may contain any text, and may also include these special variables:
+
{{todo|proof-read and fix}}
* '''%0''' - returns the entire original line.
 
* '''%1'''-'''%9''' - return the columns cut according to rules specified in the corresponding tab.
 
* '''%d''' - returns a decimal number from the {{field|Counter}}. You may specify the {{field|Start}} and the {{field|Step}}.
 
* '''%x''' - returns a lower case hexadecimal number from the {{field|Counter}}.
 
* '''%X''' - returns an upper case hexadecimal number from the {{field|Counter}}.
 
* '''%b''' - returns a binary number from the {{field|Counter}}.
 
* '''%o''' - returns an octal number from the {{field|Counter}}.
 
* '''%n''' - returns a simple newline.
 
<!--
 
* '''%i''' - returns a lower case Roman number from the {{field|Counter}}.
 
* '''%I''' - returns a upper case Roman number from the {{field|Counter}}.
 
* '''%a''' - returns a lower case letter from the {{field|Counter}}.
 
* '''%A''' - returns a upper case letter from the {{field|Counter}}.
 
-->
 
  
All these veriables might be furthermore qualified with an aligning specifier:
 
* '''<''' - aligns the entire column to the left, using spaces to fill the shorter lines from right.
 
* '''>''' - aligns the entire column to the right, using spaces to fill the shorter lines from left.
 
* '''+''' - aligns the entire column to the right, using 0 to fill the shorter lines from left.
 
* '''^''' - aligns the entire column to the center, using spaces to fill the shorter lines from both sides.
 
  
Optionally, you may choose to {{field|Modify non-empty lines only}}, if you need to keep the {{defined|empty}} lines intact.
+
Cuts portions of {{defined|lines}} from the selection and replaces the old {{defined|lines}} with new generated {{defined|lines}} according to given {{field|Columns, Numbers|Output mask}}. The {{field|Columns, Numbers|Output mask}} may contain any text, which is duplicated to every new generated line, and may include these special variables, which are computed on the fly and have the following purpose:
 +
* '''%0''' - inserts a copy of the entire original line.
 +
* '''%1'''-'''%9''' - inserts a line portion, cut from the original line according to rules specified in corresponding tab. See below.
 +
* '''%d''' - inserts a decimal number from the {{field|Columns, Numbers|Counter}}. See below.
 +
* '''%x''' - inserts a lower case hexadecimal number from the {{field|Columns, Numbers|Counter}}. See below.
 +
* '''%X''' - inserts an upper case hexadecimal number from the {{field|Columns, Numbers|Counter}}. See below.
 +
* '''%b''' - inserts a binary number from the {{field|Columns, Numbers|Counter}}. See below.
 +
* '''%o''' - inserts an octal number from the {{field|Columns, Numbers|Counter}}. See below.
 +
* '''%r''' - inserts a random number from the {{field|Columns, Numbers|Random}} number generator. See below.
 +
* '''%l0''' - inserts length, in characters, of the original line.
 +
* '''%l1'''-'''%l9''' - inserts length of a line portion, cut from the original line according to rules specified in corresponding tab. See below.
 +
* '''%n''' - inserts a single newline. Note: This variable results in generating sequence of multiple lines for each input line. Note: It is worth mentioning that all variables always work with the original line while being computed. Thus, although this variable generates a ''new line'', variable {{string|%0}} would still insert a copy of the entire original line nonetheless.
 +
* '''%%''' - inserts a single ''%'' character. Since ''%'' character is used to prefix variables, doubled ''%%'' must be used in order to get ''%'' in the results. Note: Using a simple ''%'' character, not followed by a recognized variable, is considered an error in the {{field|Columns, Numbers|Output mask}}.
  
 +
Furthermore, all variables (except ''%n'') may be supplied an aligning specifier. Aligning specifier must appear directly after the ''%'' prefix character. It is used to align values of the variable into a neat fixed-length column, and may be one of the following:
 +
* '''<''' - aligns the variable to the left, using spaces to fill the shorter lines from right.
 +
* '''!''' - aligns the variable to the center, using spaces to fill the shorter lines from both sides.
 +
* '''>''' - aligns the variable to the right, using spaces to fill the shorter lines from left.
 +
* '''+''' - aligns the variable to the right, using zeros to fill the shorter lines from left.
  
Example of an {{field|Output mask}}. This mask will cut the first column from each line and place it in the results after a decimal number, colon and a space. The numbers will be aligned to the right by zeroes, so that they all have the same number of digits:
+
Note: Aligning a variable into a fixed-length column does not necessarily guarantee a neat visual column in the results. There are two reasons for having the column scattered in the results:
{{example_start}}
+
* If proportional font is used for text displaying, it may render different characters with different extents, resulting in different visual positions of respective character positions.
{{example_body}}%+d, %1
+
* If multiple variables are used in the {{field|Columns, Numbers|Output mask}}, all of them should include an aligning specifier to ensure neat aligned columns in the results. This is because variable alignment is computed separately for each variable, insensitive to other portions of currently generated line. Therefore, if one variable results in a variable-length column, there is no guaranteed way to ensure further visual column alignment (although variables themselves would continue to get ''aligned'' neatly into ''their own private columns'').
 +
 
 +
Some variables require a {{field|Columns, Numbers|Counter}} to be defined. The tool uses {{field|Columns, Numbers|Start}} number to initialize the {{field|Columns, Numbers|Counter}} before processing the selection. Then, for each line of the selection, increments the {{field|Columns, Numbers|Counter}} by a {{field|Columns, Numbers|Step}}.
 +
 
 +
Note: {{field|Columns, Numbers|Counter}} always produces the same number for the same line, even if used multiple times per line.
 +
 
 +
Some variables require a {{field|Columns, Numbers|Random}} number generator. The generator produces decimal numbers between {{field|Columns, Numbers|Min}} and {{field|Columns, Numbers|Max}} (including {{field|Columns, Numbers|Min}} and {{field|Columns, Numbers|Max}}) every time a variable requires a random number.
 +
 
 +
Note: Unlike {{field|Columns, Numbers|Counter}}, {{field|Columns, Numbers|Random}} number generator produces a different number each time it is used, even if used multiple times for the same line.
 +
 
 +
Note: {{field|Columns, Numbers|Random}} number generator expects the {{field|Columns, Numbers|Min}} to be less than {{field|Columns, Numbers|Max}}. If {{field|Columns, Numbers|Min}} is greater or equal to {{field|Columns, Numbers|Max}}, numbers between 0 and 4294967295 are generated.
 +
 
 +
Optionally, {{field|Columns, Numbers|Modify non-empty lines only}} can be used to keep all {{defined|empty lines}} intact by this tool.
 +
 
 +
Note: The {{field|Columns, Numbers|Preview}} option can be used to toggle on/off the {{field|Columns, Numbers|Preview pane}}. The {{field|Columns, Numbers|Preview pane}} shows a small portion of lines transformed by values currently set in the tool dialog. Be aware that the preview is always generated from the current selection. If there is no selection, then there is nothing to preview. Also, since only a small portion of the selection is used for preview, alignment of columns is computed for that portion only (excluding the rest of the selection), which may result in ''shorter'' lines.
 +
 
 +
=====Cutting line portion=====
 +
 
 +
{{:Cutting line portion}}
 +
 
 +
=====Examples=====
 +
 
 +
{{example_start}}Example:
 +
{{example_body}}
 +
No;Name;Race;Age
 +
1;Amy;labrador;4
 +
2;Konie;bordercollie;3
 +
3;Kvido;mongrel;2
 +
{{example_end}}
 +
 
 +
======Simple numbering======
 +
 
 +
Example of a simple numbering {{field|Columns, Numbers|Output mask}}: {{string|%+d, %1}}. This mask will cut a line portion (specified for variable {{field|Columns, Numbers|%1}}) from each line and place it in the results after a decimal number, colon and a space. The numbers will be neatly aligned to the right by leading zeroes where necessary, in order to have the same count of digits.
 +
 
 +
{{example_start}}The variable {{field|Columns, Numbers|%1}} cuts the third column (columns separated by {{string|;}}) and the {{field|Columns, Numbers|Counter}} is set to {{field|Columns, Numbers|Start}}: {{string|1}} and {{field|Columns, Numbers|Step}}: {{string|1}}:
 +
{{example_body}}
 +
1, Race
 +
2, labrador
 +
3, bordercollie
 +
4, mongrel
 
{{example_end}}
 
{{example_end}}
 +
 +
======Columnizing trick======
 +
 +
Example of a ''columnizing'' {{field|Columns, Numbers|Output mask}}: {{string|%<1 | %2}}. If variable {{field|Columns, Numbers|%1}} cuts the first line column, and the variable {{field|Columns, Numbers|%2}} cuts the rest of the line, this mask can be used to visually ''columnize'' the list from the example above. This is done by aligning the variable {{field|Columns, Numbers|%1}} (first column) to the left, adding a glue like {{string| | }}, and then appending the rest of the line. Since this would ''columnize'' only the first column, you need to invoke this tool several times in a row, until all columns are transformed. The main reason to do it this way is that it can ''columnize'' quite many columns very quickly once this is set up correctly.
 +
 +
Note: Make sure you do not use the same delimiter for new columns that you used for old columns. Doing so would result in ''columnizing'' the first column over and over again. The main idea in this trick is to make the tool work thru old columns, converting them into new columns. The tool should not confuse new and old columns. In this example the old columns are delimited by {{string|;}} and new columns by {{string| | }}, which are mutually exclusive as required.
 +
 +
{{example_start}}The variable {{field|Columns, Numbers|%1}} cuts column 1 (columns separated by {{string|;}}), variable {{field|Columns, Numbers|%2}} cuts columns 2-4 (separated by {{string|;}} as well). After using this tool for 3 times:
 +
{{example_body}}
 +
No | Name  | Race        | Age
 +
1  | Amy  | labrador    | 4
 +
2  | Konie | bordercollie | 3
 +
3  | Kvido | mongrel      | 2
 +
{{example_end}}
 +
 +
Note: The above example only works for aligning to the left. If you want to align to the right, you can do it by ''columnizing'' backwards, from the last column to the first (i.e. the idea of working thru columns is reversed). There is no way to center the columns this way (though you can always cut each column separately into a different variable and then specify a mask, which enumerates all the variables).
 +
 +
{{tip}} Note: The {{field|Settings:Tools|Persistent selection}} setting might come handy for this technique. See chapter [[Tools page]] of the {{dialog|Settings}} dialog for more details.

Revision as of 21:01, 7 May 2011

This section is up to date for TED Notepad version 6.3.1.0.
Control page Control:feature:Columns, Numbers

Columns, Numbers... (Alt+Ctrl+Y)

This section is incomplete and wants to be finished later.
TODO: proof-read and fix


Cuts portions of lines from the selection and replaces the old lines with new generated lines according to given Output mask. The Output mask may contain any text, which is duplicated to every new generated line, and may include these special variables, which are computed on the fly and have the following purpose:

  • %0 - inserts a copy of the entire original line.
  • %1-%9 - inserts a line portion, cut from the original line according to rules specified in corresponding tab. See below.
  • %d - inserts a decimal number from the Counter. See below.
  • %x - inserts a lower case hexadecimal number from the Counter. See below.
  • %X - inserts an upper case hexadecimal number from the Counter. See below.
  • %b - inserts a binary number from the Counter. See below.
  • %o - inserts an octal number from the Counter. See below.
  • %r - inserts a random number from the Random number generator. See below.
  • %l0 - inserts length, in characters, of the original line.
  • %l1-%l9 - inserts length of a line portion, cut from the original line according to rules specified in corresponding tab. See below.
  • %n - inserts a single newline. Note: This variable results in generating sequence of multiple lines for each input line. Note: It is worth mentioning that all variables always work with the original line while being computed. Thus, although this variable generates a new line, variable %0 would still insert a copy of the entire original line nonetheless.
  • %% - inserts a single % character. Since % character is used to prefix variables, doubled %% must be used in order to get % in the results. Note: Using a simple % character, not followed by a recognized variable, is considered an error in the Output mask.

Furthermore, all variables (except %n) may be supplied an aligning specifier. Aligning specifier must appear directly after the % prefix character. It is used to align values of the variable into a neat fixed-length column, and may be one of the following:

  • < - aligns the variable to the left, using spaces to fill the shorter lines from right.
  • ! - aligns the variable to the center, using spaces to fill the shorter lines from both sides.
  • > - aligns the variable to the right, using spaces to fill the shorter lines from left.
  • + - aligns the variable to the right, using zeros to fill the shorter lines from left.

Note: Aligning a variable into a fixed-length column does not necessarily guarantee a neat visual column in the results. There are two reasons for having the column scattered in the results:

  • If proportional font is used for text displaying, it may render different characters with different extents, resulting in different visual positions of respective character positions.
  • If multiple variables are used in the Output mask, all of them should include an aligning specifier to ensure neat aligned columns in the results. This is because variable alignment is computed separately for each variable, insensitive to other portions of currently generated line. Therefore, if one variable results in a variable-length column, there is no guaranteed way to ensure further visual column alignment (although variables themselves would continue to get aligned neatly into their own private columns).

Some variables require a Counter to be defined. The tool uses Start number to initialize the Counter before processing the selection. Then, for each line of the selection, increments the Counter by a Step.

Note: Counter always produces the same number for the same line, even if used multiple times per line.

Some variables require a Random number generator. The generator produces decimal numbers between Min and Max (including Min and Max) every time a variable requires a random number.

Note: Unlike Counter, Random number generator produces a different number each time it is used, even if used multiple times for the same line.

Note: Random number generator expects the Min to be less than Max. If Min is greater or equal to Max, numbers between 0 and 4294967295 are generated.

Optionally, Modify non-empty lines only can be used to keep all empty lines intact by this tool.

Note: The Preview option can be used to toggle on/off the Preview pane. The Preview pane shows a small portion of lines transformed by values currently set in the tool dialog. Be aware that the preview is always generated from the current selection. If there is no selection, then there is nothing to preview. Also, since only a small portion of the selection is used for preview, alignment of columns is computed for that portion only (excluding the rest of the selection), which may result in shorter lines.

Cutting line portion

Cutting portion of a line is divided into two successive parts. First, columns are cut from the line, by either:

Note: Columns are cut for each line separately, therefore the total number of columns on a line may vary from line to line. If specified column number is beyond the total number of columns, empty zero-length portion is cut for such column from that line. Therefore, it is allowed to cut columns 2-7, even though some lines do not have enough columns to offer.

After the first part (cutting columns from the line), the resulting portion of the line can be further cropped by turning Use only characters option on, and specifying a range of character positions between from position and to position. This cuts off everyting before the from position and everyting after the to position.

  • Calculate the position backwards: from right to left can be used to numerate the character positions from the end of line rather than the usual way. Note, however, that this only affects how the positions are numbered before they are cropped; the text itself is not reversed.

Note: Range of character positions is always cropped after columns are cut. If a range is specified beyond currently cut columns, empty zero-length portion is cropped from that line, even if the original line continues after the cut columns. In other words, range of character positions cannot bring back what has already been cut off by previous step.

Note: There is currently no way to cut columns after cropping a range of character positions.

Note: Column preview button displays a small portion of lines transformed by current dialog values. Be aware that preview is always generated from the current selection. If there is no selection, then there is nothing to preview.

Examples
Example:

No;Name;Race;Age 1;Amy;labrador;4 2;Konie;bordercollie;3 3;Kvido;mongrel;2

Simple numbering

Example of a simple numbering Output mask: %+d, %1. This mask will cut a line portion (specified for variable %1) from each line and place it in the results after a decimal number, colon and a space. The numbers will be neatly aligned to the right by leading zeroes where necessary, in order to have the same count of digits.

The variable %1 cuts the third column (columns separated by ;) and the Counter is set to Start: 1 and Step: 1:

1, Race 2, labrador 3, bordercollie 4, mongrel

Columnizing trick

Example of a columnizing Output mask: %<1 . If variable %1 cuts the first line column, and the variable %2 cuts the rest of the line, this mask can be used to visually columnize the list from the example above. This is done by aligning the variable %1 (first column) to the left, adding a glue like , and then appending the rest of the line. Since this would columnize only the first column, you need to invoke this tool several times in a row, until all columns are transformed. The main reason to do it this way is that it can columnize quite many columns very quickly once this is set up correctly.

Note: Make sure you do not use the same delimiter for new columns that you used for old columns. Doing so would result in columnizing the first column over and over again. The main idea in this trick is to make the tool work thru old columns, converting them into new columns. The tool should not confuse new and old columns. In this example the old columns are delimited by ; and new columns by , which are mutually exclusive as required.

The variable %1 cuts column 1 (columns separated by ;), variable %2 cuts columns 2-4 (separated by ; as well). After using this tool for 3 times:

No | Name | Race | Age 1 | Amy | labrador | 4 2 | Konie | bordercollie | 3 3 | Kvido | mongrel | 2

Note: The above example only works for aligning to the left. If you want to align to the right, you can do it by columnizing backwards, from the last column to the first (i.e. the idea of working thru columns is reversed). There is no way to center the columns this way (though you can always cut each column separately into a different variable and then specify a mask, which enumerates all the variables).

Tip: Note: The Persistent selection setting might come handy for this technique. See chapter Tools page of the Settings dialog for more details.