On Jan 14, 2008 11:50 PM, DJA <[EMAIL PROTECTED]> wrote:
>
> Carl Lowenstein wrote:
> >
> > This sounds like a job for gawk. Use the and(v1,v2) operator.
> >
> > Are these fields really 4-digit hex numbers? If so, you have to
> > figure out how to AND them with 0xfff7. All bits set except the 8
> > bit.
> >
> > Too late at night to work through the rest of it. My PDP-11 instincts
> > say to use the BIC (bit clear) instruction.
> >
> The file is a simple text file, and the field is simply four ASCII
> characters. An example would be (literally) "000d" (without quotes). So,
> if I fire up vi, and change "000d" to "0005", the associated email
> becomes undeleted the next time MTB is run.
>
> I'd think a simple lookup table algorithm would do the trick?
You're right. I thought of that while half asleep, and didn't want to
work out the details. Now it sounds like a job for sed.
/^X-Mozilla Status: [:xdigit:][:xdigit:][:xdigit:][89a-f]/
oops Just found out that GNU sed version 4.1.2 doesn't understand :xdigit:.
Medium-clumsy sed script:
- - - - - - - -
/\(^X-Mozilla-Status: [0-9a-f][0-9a-f][0-9a-f]\)\([89a-f]\)/s//\1_\2/
# split off last digit
s/_8/0/ # clear the "8" bit, remove the _
splitting character
s/_9/1/
s/_a/2/
s/_b/3/
s/_c/4/
s/_d/5/
s/_e/6/
s/_f/7/
/^/p # print all lines
- - - - - - - -
My test file "text"
[EMAIL PROTECTED] dallen]$ cat text
X-Mozilla-Status: 001d
X-Mozilla-Status: 0019
X-Mozilla-Status: 0007
X-Mozilla-Status: 0009
X-Mozilla-Status: 1234
X-Mozilla-Status: 5678
X-Mozilla-Status: 9abc
X-Mozilla-Status: def0
[EMAIL PROTECTED] dallen]$ sed -n -f sedscr text
X-Mozilla-Status: 0015
X-Mozilla-Status: 0011
X-Mozilla-Status: 0007
X-Mozilla-Status: 0001
X-Mozilla-Status: 1234
X-Mozilla-Status: 5670
X-Mozilla-Status: 9ab4
X-Mozilla-Status: def0
More than you wanted to know. But if you don't want to do arithmetic,
then it takes 8 substitution statements to cover all the possibilities
89abcdef -> 01234567.
--
carl lowenstein marine physical lab u.c. san diego
[EMAIL PROTECTED]
--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-list