LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   file accidentally appended to itself, how to separate? (https://www.linuxquestions.org/questions/linux-general-1/file-accidentally-appended-to-itself-how-to-separate-440044/)

sqrt7744 04-29-2006 12:57 PM

file accidentally appended to itself, how to separate?
 
Hello gurus!

I have a problem: the transfer of a dvd iso was interrupted after 2 GB or so, and then continued and completed. Unfortunately, the "continuation" was actually just a new complete transfer appended to the preexisting incomplete file, so the final size is 6.7GB instead of 4.7GB. All the data is there, but the first 2GB is the incomplete transfer. Before I can do anything with the ISO I have to remove the redundant and incomplete first 2GB of the file. How could I do this? Due to time and bandwidth constraints it is not possible for me to begin the transfer anew.

Thanks for any help...

uselpa 04-29-2006 01:27 PM

`dd` is your friend. I'll show you on an example file, you'll have to adapt the figures to your case:
Code:

pu@slackw:~$ v DesktopBSD-1.0-x86-DVD.copy.iso
-rw-r--r--  1 root root 1343262720 2006-04-12 15:28 DesktopBSD-1.0-x86-DVD.copy.iso
pu@slackw:~$ dd if=DesktopBSD-1.0-x86-DVD.copy.iso of=part1 bs=1024 count=500000
500000+0 records in
500000+0 records out
pu@slackw:~$ dd if=DesktopBSD-1.0-x86-DVD.copy.iso of=part2 bs=1024 skip=500000
811780+0 records in
811780+0 records out
pu@slackw:~$ cat part1 part2 > part3
pu@slackw:~$ cmp part3 DesktopBSD-1.0-x86-DVD.copy.iso
pu@slackw:~$ v part*
-rw-r--r--  1 pu pu  512000000 2006-04-29 20:19 part1
-rw-r--r--  1 pu pu  831262720 2006-04-29 20:20 part2
-rw-r--r--  1 pu pu 1343262720 2006-04-29 20:22 part3
pu@slackw:~$

Of course you only need to create "part2". The other commands are there to show you that it actually works.

sqrt7744 04-29-2006 02:16 PM

nice, but...
 
Thanks for the dd tip! only problem is:
I'm not exactly sure at what byte the good data starts... somwhere around 2GB. Is it possible to search the file to find the location X at which i should use
dd if=junkfile of=goodfile skip=X ?
I'm just not familiar enough with the commands i would need for this. something like searching for the iso header, or just a repeat of the first few MB's of the file around the 2GB mark...

any ideas?
Thanks alot!

uselpa 04-29-2006 03:01 PM

You could do it the other way round: take the size of your file, take the size of the original iso, and the difference should be your offset (skip=).

sqrt7744 04-29-2006 03:23 PM

ahhh... if only i knew!
 
what a happy place this world would be if i actually knew the exact file size! I like your difference suggestion, but i'm still missing that crucial piece of information... trouble is, I won't even be able to find out the true file size until Monday since the file was coming from an office in London.
In the mean time I used dd to make a file containing the first 10MB of the junkfile, and am now trying to figure out how to use grep to search the whole file for that 10MB data chunk and report the offset, but I can't get it to work yet... is there a better way? (I thinking of giving up and writing some C code to do it)

thanks for the swift responses!

uselpa 04-29-2006 03:30 PM

You could use `xxd isofile > dumpfile` to create a text representation of your file and use a normal text editor to find your pattern.


All times are GMT -5. The time now is 07:38 PM.