Register
It is currently Sun Apr 20, 2014 2:18 am

Move files into a folder


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Fri Sep 14, 2012 1:51 pm   

Joined: Fri Sep 14, 2012 8:52 am
Posts: 8
Ive been browsing a lot of code today and reading what people have written and requested but I wanted to know how hard would it be to script a file to run on my ubuntu that will pull files out of a folder and place them in another folder.

Best explanation i can think of:
excel spreadsheet with column filled with file names and NOT the extension included
Folder 1 is empty
Folder 2 is the location of a large amount of files.
Outside with Folder 1 and Folder 2 is where the script is located with the excel spreadsheet. In the spreadsheet use the name "workorder12345" and anything with the name will be moved into the folder 1 and will work down the spreadsheet. It could even be a .txt file with the names.

Is this possible??


Top
 Profile  
 PostPosted: Sat Sep 15, 2012 5:08 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 512
hi,

excel spreadsheets are not readable outside excel. Do you mean csv file?
as source file is a single column, a flat file is good enough.

how to read a file using bash


Top
 Profile  
 PostPosted: Sat Sep 15, 2012 5:52 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Basically you want to move all files, that contain the pattern workorder12345 in their names, to another directory.
And you have a list of what's in the directory which has a large amount of files. Is this correct?

Question: Do you really need a list? How was it made?


What do you mean by « [...] will work down the spreadsheet. »?

It's not possible with an Excel file, so you'd have to use a text file, anyway.


Here is a command that does what I've understood from your post.
Code:
mv ./Folder2/*workorder12345* ./Folder1/


Top
 Profile  
 PostPosted: Tue Sep 18, 2012 8:03 am   

Joined: Fri Sep 14, 2012 8:52 am
Posts: 8
well the purpose is for a server we have a production folder with hundreds of files ready for production. Granted I do not approve this method but its not my company so... lol. I typically get requests to pull this and that for clients but I would really just like to be sent a list of names, copy and paste them in a .txt file than run a script that will pull all files related to that name for me. And yes it would be going through a few sub folders. So basically a way to go to one MAIN folder and access all content for that name.


Top
 Profile  
 PostPosted: Mon Sep 24, 2012 2:29 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
Code:
#!/bin/sh

# TXT FILE WITH FILENAMES
filenames="foo.txt"

# DIR WITH FILES
dir_files="Folder2"

# PATTERN TO LOOK FOR
fnames_pattern="workorder1234"

# TARGET DIR
dir_target="Folder1"


if [ ! -f "$filenames" ]; then
    printf "\`%s': no such file found.\n" "$filenames" >&2
    exit 1
fi

for d in "$dir_target" "$dir_files"; do
    if [ ! -d "$d" ]; then
        printf "\`%s': no such directory found.\n" "$d" >&2
        exit 1
    fi 
done

while read -r REPLY; do
    case $REPLY in *"$fnames_pattern"*)
        find "$dir_files" -type f -name "$REPLY" \
            -exec mv -- '{}' "$dir_target" \;
    esac
done < "$filenames"


I still don't see the point of getting a list if you already know the pattern and the directory's hierarchy, but well...


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 9 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