DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: IDEA: Delete first x bytes of a binary file  (Read 7,486 times)

Killeroid

  • Participant
  • Joined in 2007
  • *
  • Posts: 8
IDEA: Delete first x bytes of a binary file
« on: January 06, 2009, 07:59 AM »
I have a folder full of binary files. The first 18 bytes of each file needs to be deleted. Maybe someone can help? Thanks in advance

Killeroid

  • Participant
  • Joined in 2007
  • *
  • Posts: 8
Re: IDEA: Delete first x bytes of a binary file
« Reply #1 on: January 06, 2009, 08:29 AM »
Alright, I finally found a fix using bash and dd on linux.

Code: (bash)
#!/bin/bash
#Reads all files ending in specified extension in folder, deletes first X bytes and then saves the modified file as prefix.oldname
X=18                 #Number of bytes to delete from file
EXT=jpg             #File extension of files being modified
PREFIX=new       #The prefix prepended to the filename to after moifying the file

for file in $(echo *.$EXT); do dd ibs=$X skip=1 if=${file} of=$PREFIX.${file}; done
« Last Edit: January 06, 2009, 09:12 AM by Killeroid »

f0dder

  • [Well, THAT escalated quickly!]
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,153
    • Participated in NANY Challenge Once
Re: IDEA: Delete first x bytes of a binary file
« Reply #2 on: January 06, 2009, 06:23 PM »
Just out of curiosity: why do you need those 18 bytes (jpeg header?) deleted?
- carpe noctem

Killeroid

  • Participant
  • Joined in 2007
  • *
  • Posts: 8
Re: IDEA: Delete first x bytes of a binary file
« Reply #3 on: January 06, 2009, 06:51 PM »
All the files were encoded wrongly before transit and when i got them, all of them had 18 bytes of junk prepended to each file.

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: IDEA: Delete first x bytes of a binary file
« Reply #4 on: May 12, 2009, 01:25 PM »
what is a good Windows CLI tool to delete malformed headers like the one Killeroid used?

Original address: https://www.donationcoder.com/forum/index.php?topic=16450.0