Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 07, 2016, 04:12:32 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

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

Killeroid

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
IDEA: Delete first x bytes of a binary file
« on: January 06, 2009, 01:59:08 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
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: IDEA: Delete first x bytes of a binary file
« Reply #1 on: January 06, 2009, 02:29:41 AM »
Alright, I finally found a fix using bash and dd on linux.

Code: Text [Select]
  1. #!/bin/bash
  2. #Reads all files ending in specified extension in folder, deletes first X bytes and then saves the modified file as prefix.oldname
  3. X=18                 #Number of bytes to delete from file
  4. EXT=jpg             #File extension of files being modified
  5. PREFIX=new       #The prefix prepended to the filename to after moifying the file
  6.  
  7. for file in $(echo *.$EXT); do dd ibs=$X skip=1 if=${file} of=$PREFIX.${file}; done
« Last Edit: January 06, 2009, 03:12:10 AM by Killeroid »

f0dder

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 9,029
  • [Well, THAT escalated quickly!]
    • View Profile
    • f0dder's place
    • Read more about this member.
    • Donate to Member
Re: IDEA: Delete first x bytes of a binary file
« Reply #2 on: January 06, 2009, 12:23:26 PM »
Just out of curiosity: why do you need those 18 bytes (jpeg header?) deleted?
- carpe noctem

Killeroid

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 8
    • View Profile
    • Donate to Member
Re: IDEA: Delete first x bytes of a binary file
« Reply #3 on: January 06, 2009, 12:51:02 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,258
    • View Profile
    • Coding Snacks by Lanux128
    • Read more about this member.
    • Donate to Member
Re: IDEA: Delete first x bytes of a binary file
« Reply #4 on: May 12, 2009, 08:25:52 AM »
what is a good Windows CLI tool to delete malformed headers like the one Killeroid used?