stefanB
stefanB

Reputation: 79850

awk - how to specify field separator as binary value 0x1

Is it possible to specify the separator field FS in binary for awk?

I have data file with ascii data fields but separated by binary delimiter 0x1.

If it was character '1' it would look like this:

awk -F1 '/FIELD/ { print $1 }'

Or in script:

#!/bin/awk -f

BEGIN { FS = "1" }

/FIELD/ { print $1 }

How can I specify FS/F to be 0x1.

Upvotes: 4

Views: 4982

Answers (3)

RARE Kpop Manifesto
RARE Kpop Manifesto

Reputation: 2885

works on mawk, gawk, or nawk :

 awk -F'\1' '{ … }'

awks can properly decipher the octal code without needing help from the shell like

 awk -F$'\1' '{ … }'

Upvotes: 0

dd.
dd.

Reputation: 866

awk -F '\x01' '/FIELD/ { print $1 }'

Upvotes: 0

JSBձոգչ
JSBձոգչ

Reputation: 41388

#!/bin/awk -f

BEGIN { FS = "\x01" }

/FIELD/ { print $1 }

See http://www.gnu.org/manual/gawk/html_node/Escape-Sequences.html.

Upvotes: 8

Related Questions