Hexadecimal Field Separator 
Author Message
 Hexadecimal Field Separator

Hi gurus,
     I'm stuck with a file having separators defined as 0xff0a. I read
that I could have used \xff for FS if the hexadecimal number was 2
digits or less. But how to do it when I have 4 digits?

Thanx

Daniel



Sun, 30 Jan 2005 07:38:31 GMT  
 Hexadecimal Field Separator

Quote:
> Hi gurus,
>      I'm stuck with a file having separators defined as 0xff0a. I read
> that I could have used \xff for FS if the hexadecimal number was 2
> digits or less. But how to do it when I have 4 digits?

> Thanx

> Daniel

Try
    FS="\xff\x0a"

But, since \0a is probably going to be taken as a record separator, what
really separates the "lines" of this data file?  Or is it just 1 "line"?
(That's why I used \xfe).

    - Dan

ff0a.dat
---------
    00  74 68 69 73 FF FE 69 73-0D 0A 61 FF FE 72 65 61   this..is..a..rea
    10  6C FF FE 74 65 73 74 0D-0A                        l..test..

ffoa.awk
----------
    BEGIN{ FS="\xff\xfe" }
    { print $1 "|" $2 "|" $3 }

(output) (gawk 3.1.0/Win98 -- the \x0d\x0a gave it away)
----------
    >awk -f ff0a.awk ff0a.dat > ff0a.out
    { no ouput }

ff0a.out
----------
    this|is|
    a|real|test

which it is not, really.



Sun, 30 Jan 2005 10:41:48 GMT  
 Hexadecimal Field Separator
Thanx Dan for you idea. But it doesn't work with FS="\xff\x0a". I'm
not too sure about the line separator. I'm testing with only one line,
and when I get there I'll see what I need to do for the line
separators.

Daniel



Sun, 30 Jan 2005 22:08:15 GMT  
 Hexadecimal Field Separator

Quote:
> Thanx Dan for you idea. But it doesn't work with FS="\xff\x0a". I'm
> not too sure about the line separator. I'm testing with only one line,
> and when I get there I'll see what I need to do for the line
> separators.

> Daniel

What version of awk and O/S are you using?  And how doesn't it work?  Did
you do any diagnostics?

I mentioned that \x0a would be a problem, since this is by default a \n
record separator.  So, to awk, it looks like your data has several lines,
each ending in \xff (or maybe beginning with \xff, depeding on big-endian,
little-endian concerns.).  That is why I chose \xff\xfe.

So you have to change RS to a value that doesn't occur in the data.  Try
adding
    RS = "-"
or any other string of your choosing that does not appear in your data.

Alternatively, go ahead and let awk consider the \x0a to be a line
separator.  Then you will get single values on each "line" separated by
\x0a.  Then strip that \xff off the end (or beginning) of the line with:

    gsub(/\xff/,"")

Note that if \xff actaully appears as a data character too, then you are
messing with a screwball grammer that might need a bigger hammer.

- Dan



Sun, 30 Jan 2005 23:42:52 GMT  
 Hexadecimal Field Separator
I use AIX 4.3.3. I'm not at work, and therefore I can't see awk's
version. I'll post it tomorrow. No matter what I try, the whole line
is treated as one field. Could I email the file to you somewhere?

Thanx

Daniel



Mon, 31 Jan 2005 06:53:03 GMT  
 Hexadecimal Field Separator
Don't worry about it everyone (especially Dan). I just do a copy and
paste of the {*filter*}y character from the file, and use it in the "FS="
clause, and it seems to work!

Daniel



Mon, 31 Jan 2005 20:55:16 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Dealing with commas as a field separator AND possibly within a field

2. Multiple field separators for paranthesis not working

3. multiple field separators in AWK

4. Field Separator

5. Field Separator larger than one character

6. Field Separator not working

7. Quoted field separators

8. backslash as field separator

9. field separator

10. Problem with Field Separators

11. AWK with 2 field separators

12. Strange AWK behaviour with Field-Separators

 

 
Powered by phpBB® Forum Software