Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 07-25-2008, 07:11 AM   #1
LQ Newbie
Registered: Jul 2008
Posts: 1

Rep: Reputation: 0
Big binary file manipulation commands

Hi all,

What commands can I use to delete a block from a big binary file?

Old 07-25-2008, 10:55 AM   #2
smoked kipper
Registered: May 2008
Location: UK
Distribution: Slackware,Slamd64
Posts: 81

Rep: Reputation: 15
You could use dd. dd can use arbitrary block sizes, but it's probably easier to work in bytes in this case, unless the offset/length are an exact number of KB/MB.

This does it in two parts (before and after the doomed block).

dd if=input_file of=output_file bs=1 count=offset_of_block
dd if=input_file of=output_file bs=1 seek=offet_of_block skip=$((offset_of_block + length_of_block))
For a more hackish solution that modifies the file in place, you need to know the filesize too (make sure you backup the file first, of course, when modifying files in place).

dd if=file of=file seek=offset skip=$((offset_of_block + length_of_block)) conv=notrunc
dd if=/dev/null of=file bs=1 seek=$((filesize - length_of_block))
I thought it might work without the second line, but it didn't, it truncated the file before it could read the remaining data, so I added the conv=notrunc and then read from /dev/null to truncate the file.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Big C/C++ String Manipulation Problem ambitious88 Programming 2 09-30-2007 06:01 AM
Sending binary to a usb device using echo commands? sixgunz2 Linux - Software 0 09-04-2006 05:26 AM
file name manipulation chocolatetoothpaste Linux - Software 19 04-03-2006 10:18 AM
Why is my binary so big? jon_k Linux - Software 2 11-19-2004 01:18 AM
Some basic File Manipulation commands sureshp1980 Linux - General 2 09-24-2003 08:36 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:11 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration