(Video materials in preparation)
fixlen : Turns fields into fixed length.
Usage : fixlen <f1b>[/<f1e>].<n1><c1> <f2b>[/<f2e>].<n2><c1> ... <file>
Options : -p<c>
-s<c>
-n<string>
--sjis
--rm_fs
--rm_rs
--default=<n><c>
--zone=<z>
--pre_sign
--pre_sign_z
+<sp><sm>[<sn>]
+z<sp><sm>[<sn>]
Version : Tue Jan 9 09:02:34 JST 2024
Edition : 1
fixlen converts a file into a fixed length style by adding a padding
character ('_') to specified fields. The padding character can be
changed by the -p<c> option. For a number, the padding character is '0',
and for a pack, the padding character is 0x0.
A field specification <f1b>.<n1><c1> turns the <f1b> field to <n1>
bytes. <f1b>/<f11e>.<n1><c1> turns fields from <f1b> to <f1e> to
<b1> bytes.
Where <c1> specifies how a field is converted.
(none) Handles a field as a string.
'=' Handles a field as a string cutting an extra length.
'c' Handles a field as a string padding a shortage and
cutting an extra length.
'-' Handles a number (with a sign for a negative number).
Raising an error for a too-long number.
'+' Handles a (signed) number.
Raising an error for a too-long number.
'p' Handles a (signed) pack format number.
Raising an error for a too-long number.
'P' Handles a (unsigned) pack format number.
Raising an error for a too-long number.
'z' Handles a (signed) zone format number.
Raising an error for a too-long number.
'Z' Handles a (unsigned) zone format number.
Raising an error for a too-long number.
In the pack format, a sign + is converted to 0xc, - to 0xd, and unsigned
to 0xf. Use the +<sp><sm>[<sn>] option to change a sign. When you convert
+ to 0xa, - to 0xb, and unsigned to 0xc, set +abc as an option.
The signs of the zone format are changeable as the same as the pack format.
To change the signs use +z<sp><sm>[<sn>] option. The higher four bits
other than a sign bit can be changeable from 0xf of the default by
--zone=<z> option.
The signs of the pack format are the lowest digits, and the signs of
zone format are the lowest bytes. The position of a sign
in the zone format is changeable from (the upper four bits of) the lowest byte
by --pre_sign/--pre_sign_z option to the highest/digit bytes.
As the length of the fractional parts is that of the input field,
each length of fractional parts must be homogeneous.
The order of specification of fields is arbitrary but must not
be overlapped. The fields not specified will be printed as is. When
--default=<n><c> option is given, the fields not specified will be
changed to <n> bytes.
Use the -s<c> option to substitute a space in a field for <c>.
When the whole field is '_', the command takes the field as an empty
field and fills the field with a padding character of the same length.
Use -n<string> option to change the string taken as an empty field.
Use the --sjis option to process an input file as Shift JIS.
Use the --rm_fs option not to print a white space between fields. The --rm_rs option
suppresses printing the line feeds. Using these options, a record file of fixed
length can be generated.
To turn a single field into a fixed length.
$ cat data1
abc _ defg
ABC _ DEFG
$ fixlen 1.5 data1
abc__ _ defg
ABC__ _ DEFG
To turn serial fields into fixed length.
$ fixlen 1/3.5 data1
abc__ _____ defg_
ABC__ _____ DEFG_
To change a padding character.
$ fixlen -p@ 1/3.5 data1
abc@@ @@@@@ defg@
ABC@@ @@@@@ DEFG@
To snip a too long fields.
$ cat data2
あいう <- Note that a Japanese character consists of three bytes.
$ fixlen 1.5= data2 | xdump -
E3 81 82 E3 81 0A <- The second character lacks a byte.
To snip a string in a character boundary.
$ fixlen 1.5- data2
あ__
Pads a number with the heading '0'.
$ cat data3
123 123.00 123 123.00
$ fixlen 1/2.08 3/4.+8
00000123 00123.00 +0000123 +0123.00
To turn a file into a fixed length (including line feeds).
$ fixlen --rm_fs 1/3.5 data1
abc_______defg_
ABC_______DEFG_
To turn a file into a fixed length (including no line feeds).
$ fixlen --rm_fs --rm_rs 1/3.5 data1 | xdump -v 15 -
61 62 63 5F 5F 5F 5F 5F 5F 5F 64 65 66 67 5F : abc_______defg_
41 42 43 5F 5F 5F 5F 5F 5F 5F 44 45 46 47 5F : ABC_______DEFG_
To turn pack format numbers into fixed length.
$ cat data4
123.00 +123.00 -123.00
$ fixlen --rm_fs --rm_rs 1/3.3p data4 | xdump
12 30 0C 12 30 0C 12 30 0D
To turn pack-format numbers into fixed length (changing signs).
$ fixlen --rm_fs --rm_rs +ab 1/3.3p data4 | xdump
12 30 0A 12 30 0A 12 30 0B
To turn pack-format numbers into fixed lengths (changing the position of signs).
$ fixlen --rm_fs --rm_rs --pre_sign 1/3.3p data4 | xdump
C1 23 00 C1 23 00 D1 23 00
To turn zone format numbers into fixed length.
$ fixlen --rm_fs --rm_rs 1/3.5z data4 | xdump
F1 F2 F3 F0 C0 F1 F2 F3 F0 C0 F1 F2 F3 F0 D0
To turn zone format numbers into fixed length (changing signs).
$ fixlen --rm_fs --rm_rs +zab 1/3.5z data4 | xdump
F1 F2 F3 F0 A0 F1 F2 F3 F0 A0 F1 F2 F3 F0 B0
To turn zone format numbers into fixed lengths (changing the position of signs).
$ fixlen --rm_fs --rm_rs --pre_sign_z 1/3.5z data4 | xdump
C1 F2 F3 F0 F0 C1 F2 F3 F0 F0 D1 F2 F3 F0 F0
To turn zone format numbers into fixed length (changing a zone).
$ fixlen --rm_fs --rm_rs --zone=3 1/3.5z data4 | xdump
31 32 33 30 C0 31 32 33 30 C0 31 32 33 30 D0