(Video materials in preparation)
1x : Remove leading zeroes
Usage : 1x [-r] f1 f2 .. file
1x -d[r] string
Version : Wed Mar 14 22:39:33 JST 2018
Edition : 1
Removes the leading zeroes from the specified
field or specified string within the specified file.
(Also removes trailing zeroes after the decimal
point.)
$ cat data
0000000 Smith______ 50 F 91 59 20 76 54
0000001 Jones______ 50 F 46 39 8 5 21
0000003 Wilson_____ 26 F 30 50 71 36 30
0000004 Drake______ 40 M 58 71 20 10 6
0000005 Hawking____ 20 M 82 79 16 21 80
0000007 Penrose____ 42 F 50 2 33 15 62
$ 1x 1 data > data2
$ cat data2 <- Remove leading zeroes from first field.
0 Smith______ 50 F 91 59 20 76 54
1 Jones______ 50 F 46 39 8 5 21
3 Wilson_____ 26 F 30 50 71 36 30
4 Drake______ 40 M 58 71 20 10 6
5 Hawking____ 20 M 82 79 16 21 80
7 Penrose____ 42 F 50 2 33 15 62
-r (reverse) This option multiplies number by -1.
$ cat file
a 1 2 3 4 5
b 1 2 3 4 5
$ 1x -r 2 file
a -1 2 3 4 5
b -1 2 3 4 5
$ 1x -r 2/4 file
a -1 -2 -3 4 5
b -1 -2 -3 4 5
$ 1x -r 2 NF-1/NF file
a -1 2 3 -4 -5
b -1 2 3 -4 -5
Combines up3 and sm2 to perform subtraction
on records containing the same key.
$ cat data
a 5
b 2
$ cat data2
a 2
b 1
$ 1x -r 2 data2 | up3 key=1 data | sm2 1 1 2 2
a 3
b 1
-d directly specifies the string you want to
edit in direct mode.
$ 1x -d 0123
123
$ 1x -d 0123.400
123.4
$ 1x -d 0123.000
123
$ 1x -d 0
0
$ 1x -d -000123.400
-123.4
$ 1x -d +000123.400
123.4
$ 1x -dr 0123
-123
Removes leading zeroes in order to nullify the
automatic conversion to octal normally performed
by the shell or the awk printf command.
$ num=010 <- Interpreted as octal
$ printf '%04d\n' $num
0008
$ printf '%04d\n' $(1x -d $num)
0010
Fixed-length text strings often contain leading
zeroes, trailing zeroes and punctuation. The
1x command is helpful here.
$ cat file
a 000123.000 000345.000
b 000098.450 000100.000
$ 1x 2 3 file
a 123 345
b 98.45 100
Derivation of Command Name
Called 1x because you multiply the numeric string
by 1 to remove the zeroes.