uspTukubaiコマンドに関する様々な資料がここにあります。

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

strmrg

Name

strmrg : Merge characters into a template

Syntax

Usage :

 1.strmrg <template> <data>            (plain)

 2.strmrg -l<label> <template> <data>  (line)

 3.strmrg -h<label> <template> <data>  (hierarchy)

Option  : -n<string>

          -s<c>

          -b

Version : Tue May 31 19:43:50 JST 2016

Edition : 2

Description

Reads data from "data" or an environment variable and merges it into

the file specified as "template". Has the following three usages:

1. Merge all fields in "data" in order (normal)

2. Merges entire records at a time from "data" into the labels

   specified in "template" (by row)

3. If "data" contains heirarchical data, the data is merged into

   the labels in "template" according to the structure. (heirarchical data)

Example 1 (Normal)

Reads the fields in "data" in order (from top-left to bottom-right)

and merges them into "template" replacing %1 %2 %3 ...

$ cat data

a b

c d

$ cat template

1st=%1 

2nd=%2

3rd=%3 4th=%4

$ strmrg template data

1st=a 

2nd=b

3rd=c 4th=d

Example 2 (Normal)

By default, the underscore "_" is replaced by a null string.

To change this, use the -n option. If you use the -n option

by itself, the underscore will not be replaced by a null string.

$ cat data

a _

_ d

$ cat template

1st=%1 

2nd=%2

3rd=%3 4th=%4

$ strmrg template data

1st=a  

2nd=

3rd= 4th=d

$ strmrg -n@ template data

1st=a  

2nd=@

3rd=@ 4th=d

Example 3 (By Row)

"data" is read one record at a time, and the fields from the record are merged into

fields %1, %2, etc. in the template. Each time a new record is read, the template

starts over at the beginning. This usage is compatible with the deprecated "strmrg -r".

"strmrg -r" will be removed in the future.

$ cat data

a b c d

w x y z

$ cat template

1st=%1 2nd=%2

3rd=%3 4th=%4

$ strmrg -l template data

1st=a 2nd=b

3rd=c 4th=d

1st=w 2nd=x

3rd=y 4th=z

$ strmrg -r template data

1st=a 2nd=b

3rd=c 4th=d

1st=w 2nd=x

3rd=y 4th=z

Example 4 (By Row)

The -l allows you to set labels. In this case, the data is only merged

into the lines within template that are located between two "LABEL"

tags. The line containing the string "LABEL" is not output.

Areas not in between the two "LABEL" tags are not altered.

(Even if there is a "%num" string, it will not be converted and

will be output as-is.) The "LABEL" tag can only be used in two

places, at the start and end of the merge range. The LABEL tag

is recognized with a substring search, so be careful not to include it

in any surrounding text.

$ cat data

a b

y z

$ cat template

header %1

LABEL

1st=%1 2nd=%2

LABEL

footer %2

$ strmrg -lLABEL template data

header %1

1st=a 2nd=b

1st=y 2nd=z

footer %2

Example 5 (By Row)

By using the "strmrg -l" option repeatedly you can create HTML code for pulldown

menus and other elements very simply.

Since only one pair of "template" tags are allowed, in the example below we

work from the innermost tag outwards.

$ cat member

Smith

Jones

$ cat kbn1

Tokyo

Osaka

Yokohama$ cat kbn2

Male

Female

$ cat template

MEMBER

Name=%1

K1

Location=%1

K1

K2

Gender=%1

K2

MEMBER

$ strmrg -lK1 template kbn1 |\

  strmrg -lK2 -       kbn2 |\

  strmrg -lMEMBER - member

Name=Smith

Location=Tokyo

Location=Osaka

Location=Yokohama

Gender=Male

Gender=Female

Name=Jones

Location=Tokyo

Location=Osaka

Location=Yokohama

Gender=Male

Gender=Female

Example 6 (By Row)

By default, the "_" character is replaced with a null string.

To change this default, use option "-n".

The "-n" option must be specified after the "-l" option.

$ strmrg -lLABEL -n@ template data

Example 7(heirarchical Data)

The "-h" option is used to merge heirarchical data. You must specify a "label".

In the "template" the "%num" strings that occur within the heirarchical labels

correspond to the heirarchical key fields within "data".

For example, in the following "template", the %1 is surrounded by "LABEL-1",

and within the area surrounded by "LABEL-1" there is "LABEL-2" which encloses

%2 and %3.

In this case, the area surrounded by "LABEL-1" is only iterated and merged for the number

of times that the first field changes, and the area surrounded by "LABEL-2" is only

iterated and merged for the number of records whose second and third fields share the same

first field value.

There is no limit to the depth of the nesting. Also, the label is identified with a

substring search, so as in the example if the command line contains "-hLABEL"

then the "template" should contain heirarchical labels such as "LABEL-1",

"LABEL-2", etc.

Only one set of heirarchical labels is allowed in a "template".

$ cat data

Clarke Tokyo 10:00

Clarke Osaka 20:00

Clarke Yokohama 09:30

Jones Tokyo 16:45

Jones Kobe 15:30

$ cat template

Title %1

LABEL-1

Name=%1

LABEL-2

Location=%2 Time=%3

LABEL-2

LABEL-1

$ strmrg -hLABEL template data

Title %1

Name=Clarke

Location=Tokyo Time=10:00

Location=Osaka Time=20:00

Location=Yokohama Time=09:30

Name=Jones

Location=Tokyo Time=16:45

Location=Kobe Time=15:30

Note

By default, the "_" character is replaced with a null string.

To change this default, use option "-n".

The "-s" option option must be specified after the "-h" and "-l" options.

$ strmrg -n@ template data

$ strmrg -lLABEL -n@ template data

$ strmrg -hLABEL -n@ template data

Note (Handling of Escape Characters)

If the string "\<c>" occurs in "data" then after strmrg it is

replaced with "<c>".

If "<c>" is not escaped, it is replaced with " ".

By default <c> becomes an underscore '_'.

You can change the character that is converted to a space using

the "-s<c>" option.

If you specify -s<c> but leave <c> blank then nothing is converted

to a space.

Note (Handling Null Data)

If you specify -n<string> when strings within the data

match <string> null data is merged into the template.

$ cat template

X%1X

$ echo usp | strmrg -n usp template -

XX

$ cat template

<input type="text" value="%1" />

<input type="text" value="%2" />

<input type="text" value="%3" />

$ cat data

usp_lab

usp\_lab

______\_\_

$ strmrg template data

<input type="text" value="usp lab" />

<input type="text" value="usp_lab" />

<input type="text" value="      __" />

Note

If you specify "-" as the file name, the command reads from

standard input. This can be done for both "template" and "data".

Note

-e option has been removed.

(This is because passing variables did not depend on the file,

and was difficult to make clear.)