Register
It is currently Sun Apr 22, 2018 9:43 pm

Trying to copy specific files to specific folders.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Mar 06, 2018 4:59 am   

Joined: Fri Mar 02, 2018 12:34 pm
Posts: 2
I am trying to copy specific files to specific folders, but the file names are as such, "Long_John_Silver", "Miss_Havisham" and "Master_Pip" and the folder names are like "Long", "Miss" and "Master". So essentially I'm trying to copy the files to their respective folders e.g. Master_Pip.txt into the folder named Master. And so what I've tried to do is to capture the first word of the file name and somehow use that as a reference, however, it is at this point that I falter.

Code:

cd /home/scripts/playground/genomes_2 ;

for fldr in /home/scripts/playground/genomes_2/* ; do

    find . -name *fna.gz | while read f ; do

        #f_name=$( echo $fldr | cut -d '/' -f 7 | cut -d '_' -f 1) ;

        basenm=${fldr##*/} ; f_name=${basenm%%_*} ;

        #echo $f_name ;

        if [ "$f" == /home/scripts/playground/port/"$f_name" ] ; then

        cp $f /home/scripts/playground/port/"$f_name"/ ;

        else

        continue   

        fi

    done

done



Top
 Profile  
 PostPosted: Tue Mar 06, 2018 9:13 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
Code:
echo ${basenm%%_*}


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP