Author Topic: Tool For Finding / Deleting Byte Sequences In File  (Read 3072 times)

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Tool For Finding / Deleting Byte Sequences In File
« on: June 02, 2006, 10:01:49 am »
Hello,

is there a tool which is able to find a given byte sequence in a file and delete that sequence?

I mean something like sed for binary files, I need to do something like

sed -e '/3C 00 75 00 6C 00 3E 00 0A 00 09 00 09 00 3C 00 2F 00 75 00 6C 00 3E/d'

(I know this won't work, as sed does not do byte-level editing, it's only an example in a kind of pseudo code).

My problem is this:
I want to process a text file this way, so sed would actually be the tool to choose. But the string I want to delete contains a newline, and even with the N command of sed I was not able to create a suitable sed command.
So now I'm looking for something which works on the byte level.

Thanks for any hint

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0

sidmoraes

  • Full Member
  • ***
  • Posts: 116
    • View Profile
    • http://
Tool For Finding / Deleting Byte Sequences In File
« Reply #1 on: June 02, 2006, 01:18:21 pm »
Quote
Hello,

is there a tool which is able to find a given byte sequence in a file and delete that sequence?

I mean something like sed for binary files, I need to do something like

sed -e '/3C 00 75 00 6C 00 3E 00 0A 00 09 00 09 00 3C 00 2F 00 75 00 6C 00 3E/d'

(I know this won't work, as sed does not do byte-level editing, it's only an example in a kind of pseudo code).

My problem is this:
I want to process a text file this way, so sed would actually be the tool to choose. But the string I want to delete contains a newline, and even with the N command of sed I was not able to create a suitable sed command.
So now I'm looking for something which works on the byte level.

Thanks for any hint

daniel
[div align=\"right\"][a href=\"index.php?act=findpost&pid=129469\"][{POST_SNAPBACK}][/a][/div]

try with "tr -d ..."
SL-C1000 ( Cacko-Rom 1.23 ) + SL-C3100 ( Cacko-Rom 1.23 )
2Gb SD, usb host cable made by myself, CF modem Xircom,
CF wifi Zonet, Hawking CF 10/100 ethernet,
 USB net, USB CD-Writer Sony CRX10U, CF to PCMCIA adapter,
PCMCIA 2G disk Toshiba, USB charger self-made,
USB BLuetooth,
RH2 ( Wired control for Z ) made by myself,
Serial cable, also made ...

iamasmith

  • Hero Member
  • *****
  • Posts: 1248
    • View Profile
Tool For Finding / Deleting Byte Sequences In File
« Reply #2 on: June 02, 2006, 02:11:17 pm »
or awk if you have it in your distro
OpenBSD 4.2 -current on full 4Gb of SL-C3000
Microdrive replaced with 4Gb SanDisk Extreme III card

uth

  • Full Member
  • ***
  • Posts: 106
    • View Profile
Tool For Finding / Deleting Byte Sequences In File
« Reply #3 on: June 02, 2006, 10:41:33 pm »
I recently had a similar problem at work, replacing text that contained newlines.   I did manage to get it working with sed.  I found some examples online that helped.

When I get to work monday, I'll look it up and post my example, if you haven't found an answer by then

Meanie

  • Hero Member
  • *****
  • Posts: 2803
    • View Profile
    • http://www.users.on.net/~hluc/myZaurus/
Tool For Finding / Deleting Byte Sequences In File
« Reply #4 on: June 03, 2006, 04:29:23 am »
if you want to remove a complete line from a text file, you ca also simply use grep,

ie

grep -v "some text" ....
SL-C3000 - pdaXii13 build5.4.9 (based on pdaXrom beta3) / SL-C3100 - Sharp ROM 1.02 JP (heavily customised)
Netgear MA701 CF, SanDisk ConnectPlus CF, Socket Bluetooth CF, 4GB Kingston CF,  4GB pqi SD, 4GB ChoiceOnly SD, 2GB SanDisk SD USB Plus, 1GB SanDisk USB Plus, 1GB Transcend SD, 2GB SanDisk MicroSD with SD adaptor, Piel Frama Leather Case, GoldX 5-in-1 USB cable, USB hub, USB mouse, USB keyboard, USB ethernet, USB HDD, many other USB accessories...
(Zaurus SL-C3000 owner since March 14. 2005, Zaurus SL-C3100 owner since September 21. 2005)
http://members.iinet.net.au/~wyso/myZaurus - zBook3K

daniel3000

  • Hero Member
  • *****
  • Posts: 1003
    • View Profile
    • http://
Tool For Finding / Deleting Byte Sequences In File
« Reply #5 on: June 04, 2006, 08:07:03 am »
Quote
if you want to remove a complete line from a text file, you ca also simply use grep,

ie

grep -v "some text" ....
[div align=\"right\"][a href=\"index.php?act=findpost&pid=129570\"][{POST_SNAPBACK}][/a][/div]

Hi Meanie,

I want to remove two lines of text, but only if the first one only contains "   <ul>\n" and the second one only contains "   </ul>\n". That can occur many times in the source file.

I found bbe, which is a stream editor similar to sed, but works on binary sequences.
I'll use that one I think, since the byte sequence is alweays the same, it can be handled nicely with bbe.
bbe compiled nicely on the Zaurus.
Seems to be a useful too,. I'll make an IPK soon.

There is another approach to solve this problem, because the source file is generated from an XML using XSLT. So if I find a way to prevent the XSLT to generate these empty <ul>s, this would  be of course the more elegant solution.
But I have no clue how to do this. Have asked in some XML/XSLT forums. Maybe this will bring a working solution.

Thanks so far!

daniel
SL-C3200 with weeXpc, based on pdaXrom 1.1.0beta3
HP 200LX with MS-DOS 5.0