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

 

 

魂内検索

DOCUMENTS

COMMAND

FORUM

UEC DOCS

VIDEO

 

Alphabetical list

(Video materials in preparation)

fcols(USP)

Name

fcols : Fix (align) the columns in a text file

Synopsis

Usage   : fcols n1 n2 .. <filename>

          fcols [--] <filename>

          fcols -v <filename>

Option  : -T<tmpdir>

Version : Wed Sep 19 13:56:03 JST 2018

Description

This tool aligns the column widths of all of the fields in the specified

file or standard input.

The tool can automatically calculate the column width of each field or you

can specify the column widths manually.

If you specify the -T<tmpdir> option, the command will create

the temporary file into diretory <tmpdir> when the temporary file

is needed. The default directory is /tmp.  The temporary file is

needed when the input is not a regular file.

Example 1

Automatically calculates the widest column width for each field in the

specified file and outputs columns adjusted automatically.

$ cat data

01 Massachusetts 01 Boston 91 59 20 76 54

01 Massachusetts 02 Worcester 46 39 8 5 21

01 Massachusetts 03 Springfield 82 0 23 84 10

02 New_York 04 Manhattan 30 50 71 36 30

02 New_York 06 Queens 58 71 20 10 6

04 Pennsylvania 13 Philadelphia 92 56 83 96 75

$ fcols data   (Right Justified)

01 Massachusetts 01       Boston 91 59 20 76 54

01 Massachusetts 02    Worcester 46 39  8 5 21

01 Massachusetts 03  Springfield 82 0 23 84 10

02      New_York 04    Manhattan 30 50 71 36 30

02      New_York 06       Queens 58 71 20 10 6

04  Pennsylvania 13 Philadelphia 92 56 83 96 75

$ fcols -- data (Left Justified)

01 Massachusetts 01 Boston       91 59 20 76 54

01 Massachusetts 02 Worcester    46 39 8  5 21

01 Massachusetts 03 Springfield  82 0 23 84 10

02 New_York      04 Manhattan    30 50 71 36 30

02 New_York      06 Queens       58 71 20 10 6

04 Pennsylvania  13 Philadelphia 92 56 83 96 75

Example 2

Manually specify the column width for each field.

Specify the column widths as arguments to the command starting with the first

field.

        ↓2nd field width

fcols n1 n2 n3 ・・・・nNF

     ↑               ↑

1st field width   Last field width

Column widths are specified in single-byte characters. For double-byte characters

multiply by two.

fcols 4 specifies four single-byte characters and 2 double-byte characters.

$ fcols 2 13 2 12 2 2 2 2 2 data

>> Same outout as Example 1

Example 3

Normally columns are right-justified. To left-justify a column add a "-"

to the column width.

The 2nd and 4th fields are left justified.

$ fcols 2 -13 2 -12 2 2 2 2 2 data

01 Massachusetts 01 Boston       91 59 20 76 54

01 Massachusetts 02 Worcester    46 39  8 5 21

01 Massachusetts 03 Springfield  82 0 23 84 10

02 New_York      04 Manhattan    30 50 71 36 30

02 New_York      06 Queens       58 71 20 10 6

04 Pennsylvania  13 Philadelphia 92 56 83 96 75

Example 4

If you have multiple fields in a row with the same column width, you can

specify "column width"x"number of fields" in order to simplify the command.

"fcols 3x4" is the same as "fcols 3 3 3 3".

You can use "NF" (the total number of fields in the row) and specify "NF-xx".

$ fcols 2 -13 2 -12 2x5 data

$ fcols 2 -13 2 -12 2xNF-4 data

>> Same output as Example 3

Example 5

The "-v" option displays the widest column width in the file for each field.

$ fcols -v data

2 13 2 12 2 2 2 2 2

$ fcols $(fcols -v data) data

>> Same output as Example 1