Well, my first real question, sorry for asking such a big thing. Maybe, with some help I can figure out the missing pieces by myself. I have spend some evenings on figuring this out so my description can be a bit uberthought - please ask if it's too chaotic :P
I want to write a bash script (or python script) which helps me sorting a download folder.
This should be done by copying similar named files in subfolders named after the first 15 chars of the filename or create a subfolder if there is none present.
Then the script should make a new file in the (new) subfolder where a part of a logfile gets pasted including other text.
At last, it should copy the matching files to the subfolder.
To be more concrete I thought of the following steps:
Code:
check if there is a subfolder which name is similar to the first (15*) chars of a file in the script folder
if not create a subfolder and name it after the first 15* chars of the lonleyfile
find in ./.scripts/text_file.log a line beginning which is similar to (the first 15 chars of) the subfolder_names from the script folder
get the part_of_the_line_after the comma ","
create a new file in the subfolder
paste a piece of text and text_including$part_of_the_line_after into a new_file_in_subfolder.desktop named after the subfolders first 15 letters
check if there are any files which are names similar with the subfolder_names and copy them into the created subfolder.
For example:
Code:
$ls
Abelmosch 123
Acyandstuff
Blahontea
Anther_All_pics
Greenandfunny
NotInTHEGARDEN01
Abelmosch 123.jpg
Blahontea.wmv
Green_introductino to gardening.pdf
...
Code:
cat specific_text_file.log
Downloaded Flower Pics.log
Abelmosch 123,Abelmoschus
Acyandstuff,Acalypha
Blahontea,Anisodontea
Anther_All_pics,Anthericum
Greenandfunny,Anaphalis
NotInTHEGARDEN01,Clitoria
...
*runningmagicscript*
Code:
$ls -R
.:
Abelmosch 123
Acyandstuff
Blahontea
Anther_All_pics
Greenandfunny
NotInTHEGARDEN01
./Abelmosch 123
Abelmosc.desktop
Abelmosch 123.jpg
./Acyandstuff
Acyandst.desktop
./Blahontea
Blahonte.desktop
Blahontea.wmv
./Anther_All_pics
Anther_A.desktop
./Greenandfunny
Greenan.desktop
Green_introductino to gardening.pdf
./NotInTHEGARDEN01
NotInTHE.desktop
Code:
cat ./Greenandfunny/Greenan.desktop
[Desktop Entry]
Version=1.0
Type=Link
URL=https://en.wikipedia.org/wiki/Anaphalis
I have a snippet which does some part of the job.
script2folder.sh
Code:
#!/bin/bash
find * -prune -type f ! -name "*.sh" | while read file;
do
f=$(basename "$file")
f1=${f%.*}
mkdir "$f1"
# mv "$f" "$f1"
done
Two points I assume important:
a) the string containing the file/subfolder name should be similar, not exactly matching.
b) the script should check if the things it creates already exist, if so, goto next step
Maybe it is better to check if the whole filename matches and exclude spaces, underscores and file endings (like all $foo after the last dot).
Thank you for reading this far