UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2006-04-21 06:57 PM

JanL
Member
Registered: 2006-04-21
Posts: 3

Re: cut fields where field separator is hex 1f

Hi,
I am trying to pull fields out of a data file which has weird field separators. When I vi the file, I see them as ^_ which I have discovered is a hex 1f.
I have tried doing ths:
cut -f11 -d'^_'  filename  but it says invalid field separator
I also tried other variations on the -d and none of them worked.

SO then I tried using awk thinking I might be able to get the FS to accept this weird ^_, but that didn't work either.

Does anyone out there know how to do this?

Thanks,
Jan

Offline

#2 2006-04-21 07:06 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: cut fields where field separator is hex 1f

Try this (totally untested):

cut -f11 -d`echo -e '\x1f'` filename

Offline

#3 2006-04-21 07:10 PM

JanL
Member
Registered: 2006-04-21
Posts: 3

Re: cut fields where field separator is hex 1f

sorry...it didn't work...this one is annoying...I've not seen this type of file separator used before!!!


-> cut -f11 -d`echo -e '\x1f'` out
cut: invalid delimiter

Offline

#4 2006-04-22 09:02 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: cut fields where field separator is hex 1f

Strange...  It works for me:

[agrajag]$ od -Ax -tx1z crap
000000 75 67 68 1f 63 72 61 70 1f 6a 75 6e 6b 0a        >ugh.crap.junk.<
00000e
[agrajag]$ cut -f1 -d`echo -e '\x1f'` crap
ugh
[agrajag]$ cut -f2 -d`echo -e '\x1f'` crap
crap
[agrajag]$ cut -f3 -d`echo -e '\x1f'` crap
junk

What system are you on?  Linux or something else?  Maybe it's just that GNU "cut"
can handle it, but whatever one you're using can't...  Or, maybe your "echo" doesn't
support "-e"?  Try doing this:

[agrajag]$ echo -e '\x1f' | od -Ax -tx1z
000000 1f 0a                                            >..<
000002

If you don't see output like that, then it's probably your "echo"...  In which case,
try substituting "printf" in place of "echo -e"...  Or, perhaps instead of using "\x1f",
try the octal version: "\037"...  Maybe it just doesn't like "\x" hex values... *shrug*

Offline

#5 2006-04-23 04:17 PM

JanL
Member
Registered: 2006-04-21
Posts: 3

Re: cut fields where field separator is hex 1f

I am on Solaris. What worked for me was to do a normal cut, but include
Ctrl v before the Ctrl _   By this I mean I actually used the Ctrl key on my keyboard for both. Nothing shows up when I hit the Ctrl-v, but it sure does work! 

It was explained to me like this:

"to insert a control character on the command line, you need to do a
control-v first.  so, do a control-v control-_ for your delimiter"

Offline

Board footer

Powered by FluxBB