Sorry to say that even with the wildest guessing I can't understand WHAT you want to do.
What is a "hexadecimal" file (if it's NOT a binary file)?
What is a chain ? Is it a character string?
Your input file has at least a human readable time stamp, so it's scarcely a real binary, nor, due to all those (binary) zeroes, a real text file. With your command pipe, you'll remove 16 (sort of) randomly positioned bytes - to what avail?
Making lots of assumptions here, but what about this? (seems too complex in sed for my taste):
xxd file | awk '{
# Only fields 2 thru 9 are the hex values we need to check.
for(Idx=2;Idx<=9;++Idx){
# Look for the problem data.
if($Idx=="493a"){
# Note stop location, so we can pad the rest of the line for xxd.
Stop=Idx
# Split off the portion before the problem data into an array, what we want will be in the first element.
split($0,PartLine," 493a ")
# Continue from where we left off and pad the line out with 0000
for(Jdx=Stop;Jdx<=9;++Jdx){
RemLine=RemLine " 0000"
}
# Output the portion before the problem data as well as the pad data.
print PartLine[1]RemLine
# Stop processing the file here.
exit
}
}
# Output any non-applicable lines
print
}' | xxd -r -p
Are you sure you need that "-p" option on xxd?
Also, assuming the hex 493a ":I" will only occur on the even boundary, otherwise gets more fun.
In addition to what RudiC said, note that the sed portion of your script will not only remove every line that has the hexadecimal value 0x493a at an even numbered pair of bytes, it will also remove any line that contains the string "493a" in the text portion of the output and any line that contains 493a anywhere in the address field. And, it will not remove lines where 0x49 and 0x3a are adjacent byte values starting at an odd numbered byte address.
And, like RudiC... I have no idea what output you are hoping to produce.
Not sure if this is what is required...
Shell builtins around xxd as xxd has some strange quirks in spitting out a pure hexdump...
OSX 10.7.5 default bash terminal.
#�/bin/bash
# bin_edit
# Create a working binary file...
echo ""
BIN_ARRAY=( 00 00 00 00 00 00 00 00 00 00 00 00 49 3a 00 4f 63 74 20 32 38 20 32 30 31 35 20 31 39 3a 32 34 )
for n in {0..31}
do
echo -en "\x${BIN_ARRAY[$n]}"
done > /tmp/bin
# Prove binary exists...
xxd /tmp/bin
# Now create the edit...
HEX=( $( xxd -cols 1 -p /tmp/bin ) )
# Now edit...
NEWHEX=""
for n in $( seq 0 2 ${#HEX[@]} )
do
OLDHEX="${HEX[$n]}${HEX[$(($n+1))]}"
if [ "$OLDHEX" = "493a" ]
then
:
else
echo -en "$NEWHEX$OLDHEX"
fi
done > /tmp/texthexdump
echo ""
# 0x493a now removed creating new binary file...
read -r line < /tmp/texthexdump
n=0
while [ $n -lt ${#line} ]
do
echo -en "\x${line:$n:2}"
n=$(($n+2))
done > /tmp/newbin
xxd /tmp/newbin
echo ""