Previous: , Up: Usage Examples   [Contents][Index]


5.12 Extracting numeric values - using getnum

The getnum operation extracts a numeric value from the field:

$ echo zoom-123.45xyz | datamash getnum 1
123.45

getnum accepts an optional single-letter TYPE option:

getnum:n

natural numbers (positive integers, including zero)

getnum:i

integers

getnum:d

decimal point numbers

getnum:p

positive decimal point numbers (this is the default)

getnum:h

hex numbers

getnum:o

octal numbers

Examples:

$ echo zoom-123.45xyz | datamash getnum 1
123.45

$ echo zoom-123.45xyz | datamash getnum:n 1
123

$ echo zoom-123.45xyz | datamash getnum:i 1
-123

$ echo zoom-123.45xyz | datamash getnum:d 1
123.45

$ echo zoom-123.45xyz | datamash getnum:p 1
-123.45

# Hex 0x123 = 291 Decimal
$ echo zoom-123.45xyz | datamash getnum:h 1
291

# Octal 0123 = 83 Decimal
$ echo zoom-123.45xyz | datamash getnum:o 1
83