Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Find all pdf an get make a folder from filename substring

Tags
shell scripts

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-14-2017
Find all pdf an get make a folder from filename substring

Hi ,

i need your advice.

i will find all *.pdf files and make a folder for every different prefix of file names.

for example:

Code:
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 folder.

i hope you kann help me

so long Maxwill

PS: sry for my engilsh


Moderator's Comments:
Find all pdf an get make a folder from filename substring Please use CODE tags as required by forum rules!

Last edited by RudiC; 11-14-2017 at 04:16 AM.. Reason: Added CODE tags.
# 2  
Old 11-14-2017
Welcome to the forum.

Any attempts / ideas / thoughts from your side?
# 3  
Old 11-14-2017
Hi,

yes i have bulid this

Code:
VAR=`find . -name *.pdf -print`
for file in $VAR;
do
   fname=`basename $file`
   prefix=${fname%_*}
   mkdir -p ./$prefix
   mv $file ./$prefix/
done

but i get a problem when i have files like :
Code:
test_234234_22433.pdf

i will only the first letters until the first underscore.

so long Maxwill

Last edited by Maxwill; 11-14-2017 at 05:41 AM..
# 4  
Old 11-14-2017
Have you tried:
Code:
prefix=${fname%%_*}

?
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find a filename of a folder? cmarzan UNIX for Dummies Questions & Answers 1 03-18-2015 03:06 AM
How can i make my cron/script to generate a log filename with timestamp in it ? System Admin 77 Shell Programming and Scripting 5 01-14-2015 12:57 PM
Command - filename as arguments - make executable to all users. Reddax UNIX for Dummies Questions & Answers 3 11-05-2014 09:09 AM
How to make parallel execution on folder ? rspwilliam Shell Programming and Scripting 6 10-28-2014 08:48 AM
Mv series out of mixed folder & identify substring Zack Shell Programming and Scripting 3 02-22-2014 05:10 PM
Compare filename to file folder sw_and Shell Programming and Scripting 7 04-02-2012 05:30 AM
Checking files in folder using starting string for filename chetancrsp18 Shell Programming and Scripting 10 07-25-2011 02:18 PM
How to make a make from other folder Grobix UNIX for Dummies Questions & Answers 7 10-21-2009 03:16 PM
Find all text files in folder and then copy to a new folder cgkmal Shell Programming and Scripting 4 06-20-2009 01:12 PM
Jar/Tar to a diffent folder/same folder w/ filename reis3k UNIX for Dummies Questions & Answers 0 03-25-2009 10:00 AM


All times are GMT -4. The time now is 06:18 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password