0

I have several thousand eBooks named like AuthorFirstName AuthorLastName Title XX.pdf, where xx are number from 1-99 (volume number).

Author tilte name can be of multiple word so here i want to move copy the files to folder with the name AuthorFirstName AuthorLastName title. Everything except the number should be the folder name, so that all volumes of the eBook come in same folder.

For example

root.....>AuthorFirstName AuthorLastName Title>AuthorFirstName AuthorLastName Title XX.pdf
fedorqui
  • 275,237
  • 103
  • 548
  • 598
user2175309
  • 1
  • 1
  • 3

3 Answers3

1

You can use a mix of find, sed and bash script for the task. You have to write it on your own though and ask for help if you fail.

You can also try some ready tools for mass moving/renaming like these: http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/mass-rename.html Never used one of these though.

akostadinov
  • 17,364
  • 6
  • 77
  • 85
1

I would try with this:

for folder in $(ls | sed -r "s/(.*) ([0-9]{1,2})/\1/" | uniq)
do 
    mkdir $folder
    mv $(find . -name "$folder*") $folder
done    

I don't know if this is correct, but it may give you some hints.

edit: added uniq to the pipe.

darxsys
  • 1,560
  • 4
  • 20
  • 34
0

Use a loop as shown below:

find . -type f -name "*pdf" -print0 | while IFS= read -d '' file
do
    # extract the name of the directory to create
    dirName="${file% *}"

    # create the directory if it doesn't exist
    [[ ! -d "$dirName" ]] && mkdir "$dirName"

    mv "$file" "$dirName"
done
dogbane
  • 266,786
  • 75
  • 396
  • 414