On 01-Oct-10 07:55:02, Mark Rogers wrote:
On 30/09/10 18:41, Ted Harding wrote:
It seems Mark wants to set bit 4 to 0, presumably whatever the first 3 bits may be. Is that correct?
That is correct.
The 0009 -> 0008 replacement is fine as far as it goes but it misses all the ones that have other bits set; deleting the status means that there's more rubbish to sort through but at least avoids missing anything.
Also, Mark, how many of the bits would be 1 in this? Since bit 4 can be 1, and bits 1, 2, 3 could be 0 or 1, you could be up to 0015 on those 4 bits alone. Will you be using higher-order bits as well? E.g. with bit 5 in play, you can go up to 0031, with bit 6 up to 0063, etc.
In principle any could be set, although I did grep | sort | uniq the X-Mozilla-Status line and (from memory) there were only about 12 variations in total.
Or is that 4-digit number really in hex? So it could have value 000F, 00BF, 0ABF, ...
Yes, it would be hex.
In principle, your task can be dome in 'awk', but the details would depend on the answers to these questions!
I'd be interested in how to do it in awk purely as an exercise to improve my awk skills, but the actual need has passed by deleting all the status lines. I do still have a backup file to test any theories on though!
-- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450
The following shows the principle of the thing. There is no built-in function in 'awk' to handle hex arithmetic, do I've had to fudge it. Also, the following code only deals with the 4th hex digit in the final field and leaves positions 1,2,3 unchanged. It could of course be extended so as to perform required modifications of all of them!
Paste the following (between the "###..." lines) into the command line: ############################################################# cat << EOT | awk '/^X-Mozilla-Status:/{ temp1=substr($2,1,3) ; temp2=substr($2,4,1) if(temp2=="8"){temp3="0"} if(temp2=="9"){temp3="1"} if(temp2=="A"){temp3="2"} if(temp2=="B"){temp3="3"} if(temp2=="C"){temp3="4"} if(temp2=="D"){temp3="5"} if(temp2=="E"){temp3="6"} if(temp2=="F"){temp3="7"} $2=temp1 temp3 print $1 " " $2 next } {print $0}'
This is garbage X-Mozilla-Status: 0008 This is more garbage X-Mozilla-Status: 1329 And still more X-Mozilla-Status: 236A And more again X-Mozilla-Status: A15B X-Mozilla-Status: 2C4C X-Mozilla-Status: FE3D X-Mozilla-Status: BD2E X-Mozilla-Status: 231F And this is the last garbage EOT #############################################################
and you should see the following output:
This is garbage X-Mozilla-Status: 0000 This is more garbage X-Mozilla-Status: 1321 And still more X-Mozilla-Status: 2362 And more again X-Mozilla-Status: A153 X-Mozilla-Status: 2C44 X-Mozilla-Status: FE35 X-Mozilla-Status: BD26 X-Mozilla-Status: 2317 And this is the last garbage
Showing that the "garbage" lines (whatever they happen to be) come through unchanged, while the lines matching "^X-Mozilla-Status:" have their second field modified so that bit 4 of the 4th hex digit is set to 0.
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 01-Oct-10 Time: 11:07:31 ------------------------------ XFMail ------------------------------