I've made some backups of my previous systems using Deja Dup (duplicity). In my current distribution it's not available, so I've simply extracted the data. Now in order to make that data meaningful again I have to cat the files like that:
cat ? ?? > file
Question marks are dependable from number of files of course.
The structure of extracted data is like this:
so the filename is a folder and within that folder there are numbered files (like 1, 2..20..300..etc). Different files (which now are folders) have different number of those numbered files inside them.
So I thought to get all directories where . is present. Then if there are no subdirectories in that directory cat all files to one, give that file folder name (because it's the actual file name), transfer it one directory upwards (..) and then delete that directory (the one used to create a file with filename)
So I started writing script, but I have some issues with it:
directories = "$(find . -type d)" for i in "$directories" do fdir = "$i" rdir = "$(dirname "$i")"; fname = "$(basename "$i")"; if [[ "$(basename "$i")" == *"."* ]] then cd "$i" FILECOUNT="$(find . -type f -maxdepth 1 -printf x | wc -c)" DIRCOUNT="$(find . -type d -maxdepth 1 -printf x | wc -c)" DIRCOUNT=$(( DIRCOUNT - 1 )) if DIRCOUNT == 0 then if FILECOUNT != 0 then # >> this is the problematic part DIGITS = "$(grep -o "[s|S]" <<<"$x" | wc -l)" cat "$QUESTIONMARKS" > "$fname" mv "$fname" "$rdir" +"/"+ "$fname"+".restored" rm * cd .. rmdir fname mv "$fname"+".restored" "$fname" # << end of problems fi fi fi done
So the problem is - how do I generate question marks depending on file number in directory? if there is a 1 digit file number in directory then command should look like this:
cat ? > file
if there is 2 digit file number in directory, then:
cat ? ?? > file
if 3, then:
cat ? ?? ??? > file
You get the idea..
After this, I wrote a list of commands which should proceed, although - do I simply add them like this or do I have to wrap them to () ?
Is it ok to cd in such script? Will I not get into some issues?
Any other possible solutions to achieving this?