Mv series out of mixed folder & identify substring
Dear unix-Community,
great to be here!
Actually i try to build a script to sort out my serials into an series-folder.
Reason is: plex cant handle mixed folder filled with other stuff than series only.
First shot was ls in combination with grep and regex.
Got no positiv result.
Ok - Now it would be great to create a new folder named with the titel of the serial. but it's a bit difficult to get the name as substring before the SxxExx-Part (or including the Sxx one).
Are you trying to: 1. Find files with the below pattern in the name
2. Create a subdirectory named: SerialTitel.xxx where xxx is first 3 positions of pattern starting with the s or S
3. Move file(s) found to this new subdirectory
Find file(s) named:
Code:
.*[sS][0-9][0-9][eE][0-9][0-9].*
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match a single character present in the list “sS” «[sS]»
Match a single character in the range between “0” and “9” «[0-9]»
Match a single character in the range between “0” and “9” «[0-9]»
Match a single character present in the list “eE” «[eE]»
Match a single character in the range between “0” and “9” «[0-9]»
Match a single character in the range between “0” and “9” «[0-9]»
Match any single character that is not a line break character «.*»
Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
hi spacebar. Thanks for your reply
i got a bit more:
Sample Filename: unix.com-doku.S01E01.codec #(folder or file)
i have read myself a bit into awk and got partial success.
to get your intermediate directory names, you could try:
Code:
${FILE%[Ee][0-9][0-9].*}
If I understood what you're trying to do correctly, the following shell script seems to do what you want. (I usually use the Korn shell, but this script will work with any shell that performs basic POSIX conforming parameter expansions. It was tested with ksh and bash.)
Code:
#!/bin/ksh
# Set pathname for parent destination directory.
DestDir="${PWD}/sorted"
# Move into source directory (named by 1st parameter; default: ./src)
cd ${1:-src}
# Process list of files containing desired pattern...
ls *.[Ss][0-9][0-9][Ee][0-9][0-9].* | while IFS="" read -r src
do if [ ! -f "$src" ]
then continue # Skip all but regular files.
fi
# Extract subdirectory name in destination parent directory from $src:
MidDir="${src%[Ee][0-9][0-9].*}"
# Create the destination directory if it doesn't already exist.
if [ ! -d "$DestDir/$MidDir" ]
then mkdir "$DestDir/$MidDir"
fi
# Move the source file to its new destination.
mv "$src" "$DestDir/$MidDir"
done
Obviously, you should verify that the cd. mkdir and mv commands all succeed and this script should exit with a non-zero exit status if any errors were detected.
Hi ,
i need your advice.
i will find all *.pdf files and make a folder for every different prefix of file names.
for example:
test_21424234.pdf
new_242342.pdf
at the and i will that i create ( if not exits ) a new folder "test" and "new" , afterwards i will move the file in this new... (3 Replies)
Hi!
I have a difficult problem, to step up a unknown version number in a text file, and save the file. It would be great to run script.sh and the version gets increased.
Example the content of the textfile.txt
hello
version = x
bye
This include three steps
1. First find the char after... (2 Replies)
Hi everyone I am new to the forums.
I haven't done much linux myself but I have been asked if I can do the following.
Write a linux script that needs to scan a certain folder every x amount of minutes and if there is a file in the folder then it needs to call a different script.
Is this... (2 Replies)
Hi All,
I am trying to write a script to get the user information & the command executed.
I tried something like this :
w | sort | awk '{print$5$6$7}'
My requirement is to identify the users who execute the same command at same time.
I need the user name & the... (2 Replies)
Hello folks,
I am trying to accomplish the following:
1. Create home folders for each user
2. Create a public folder where all users can access
3. Use Samba as a domain controller.
I have successfully completed issue 1. But I can't get the second issue to work. Below is my config file.... (0 Replies)
Hello,
Is there anyway to tell which set of Hitachi array the disks belong to? I'm remotely located so I cannot do the physical check.
The possible Hitachi arrays are: AMS1000 and 9570
This is what I see on the format:
2. c2t50060E800475EA02d1 <HITACHI-OPEN-V*9-SUN-5007 cyl 65533 alt 2... (0 Replies)