cat command - for every combination of 6 files, merge into a single image file.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
cat command - for every combination of 6 files, merge into a single image file.
Hi this is my first question - apologies, I searched but couldn't find anything similar. (Though I guess it is covered already - I just don't know how to ask correctly).
I have 6 image files part.img, part1.img.. .. part5.img - each of which is 2GB in size.
To combine all of these into a single image file is possible with the following:
Code:
cat part*.img >> Result.img
This has failed to generate an image that can be mounted..
I'm just curious is all and wanted to try to merge each segment file in every possible combination and save that as a Result[n].img file..
..then try to mount the individual results (i doubt it will work any way.. give an image that can be mounted). I just wanted to know if this is possible from the command line (to automate) or should I really be doing this in python or similar?)
Thanks.
(edit: I guess the question was, "Can you put a FOR loop into the command line" and the answer looks to be yes.. probably in a bash script?
Code:
for i in {1..5}; do COMMAND-HERE; done
Last edited by Numptius; 06-25-2018 at 12:55 PM.
Reason: Awesome Machine noticed that I was missing a '>' (thanks AW - well spotted!)
Hmmm. It's certainly possible with fairly simple loop constructs, but I'd be inclined to enforce collating sequence by renaming part.img to part0.img (that's a zero). Then try that cat.
Looks definitely suspect that naming ...
Hi Syg00 - this is part of an effort to restore data from an Android mobile (Cubot) - They generate 6 userdata backup files during recovery, each named userdata_ddmmyy_hh_ss.backup and then userdata_ddmmyy_hh_ss.backup1 and so on..
I've converted to .img and skipped the first 512 bytes, which when merged, should give a mountable image file (that's reported to work for other phones) but not Cubots.. I just thought, what if the .backup + .backup1 + .backup3 was intentionally misleading..
Last edited by Numptius; 06-24-2018 at 09:46 AM.
Reason: spelling
make copies of them first, then keep the originals in a safe, different place, then go into experimentation mode with your copies, if it messes up, make another set of copies until you get it figured out. command line or script both will work.
if you use a part1 part2 ... etc.
you can use a part of this to get the next file by its number.
Code:
userx@manjaro:~/test
$ for i in 1 2 3 4 ; do touch file"$((c++))" ; done
$ ls
file0 file1 file2 file3
make copies of them first, then keep the originals in a safe, different place, then go into experimentation mode with your copies, if it messes up, make another set of copies until you get it figured out. command line or script both will work.
if you use a part1 part2 ... etc.
you can use a part of this to get the next file by its number.
Code:
userx@manjaro:~/test
$ for i in 1 2 3 4 ; do touch file"$((c++))" ; done
$ ls
file0 file1 file2 file3
Thanks, that's a nice example. Much appreciated. Cheers.
If you use the wildcard, you need '>>', so each file doesn't write over the previous one. Then it should work.
Cheers, I was hoping it would work (it is definitely the correct syntax and I'll update the original post).
I read on the XDA forum that there's something unique about the headers for the Cubot '.backup[n]' files.. It's from my own phone, so it's no big deal.. it was just a learning exercise (mainly because every other Android device I own, either doesn't list 'Backup Userdata' as a recovery option or the phone is seemingly beyond (without jtag) repair.. Riff box looks likely in the near future..
trying to get started on the bash script but woman and online banking are blocking
Hmmm. It's certainly possible with fairly simple loop constructs, but I'd be inclined to enforce collating sequence by renaming part.img to part0.img (that's a zero). Then try that cat.
Looks definitely suspect that naming ...
I think you and BW's link are my next efforts.. reading on the aforementioned link.. 'split' (which i've not had cause to use) has a note about the correct naming of files... if split hasn't done the naming, then there is no guarantee that cat should give a viable output? (i hope the answer is yes)
Last edited by Numptius; 06-25-2018 at 02:34 PM.
Reason: 'hope' not 'think'
#!/bin/bash
# Shell script to generate all combinations of image files part 1 to part 6
echo "input the desired output filename:"
read ofilename
clear
for i in {6..1..1}
do
echo $i
for j in {6..1..1}
do
echo $j
for k in {6..1..1}
do
echo $k
for l in {6..1..1}
do
echo $l
for m in {6..1..1}
do
echo $m
for n in {6..1..1}
do
echo $n
cat >> $ofilename <<EOF
part$i.img
part$j.img
part$k.img
part$l.img
part$m.img
part$n.img
EOF
echo "$ofilename $i$j$k$l$m$n"
done
done
done
done
done
done
I've just run that, was going to append the $i$j$k$l$m$n to the filename to create the individual files.
Running it with very small test files.. it did work (i think) and planned to add a bit more at the end to mount and check each file.. delete if no good.. perhaps should finish it anyway but it's glaringly obvious that if the final result was a 12GB img file.. errr.. that's a long time to do on even my reasonable/modest desktop.. it can do one 12GB cat combination in around 4 minutes but the vast qty of combinations.. or am i being soft..
I got three months of runtime in my head.. and that's not including the mounting/checking time??? mmm thanks for all your help.. i don't know who should get the solved points.. BW was very helpful but i'd still be over catting files (with out Awesome Machine's eagle eye.. toss of a coin.. Tails.. AwesomeMachine... (hold on.. how do you even mark a thread as solved..)
I'm an idiot, hence the name.. it's not 3 months (blaming it on the heat or the lack of sleep).. it's 3 months for every combination (reusing the digits 1 2 3 4 5 6) it's a permutation problem? 6! = 720 = approx 2.5 days.. less than a week (for 12GB output file) which seems much better.. or at least worth solving...
Last edited by Numptius; 06-27-2018 at 01:25 PM.
Reason: ? added
NB: I'm not really as bothered about mounting a viable image now, not as much as generating the permutations and checking.. just a learning exercise.. I've done a little programming but relatively new to bash..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.