Search for a file in all directories and place the file in that directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for a file in all directories and place the file in that directory
# 1  
Old 05-11-2016
Search for a file in all directories and place the file in that directory

Hi All,

Daily I am getting the updated file.
I have to search for this file in all directories and sub directories.
If the file existed in a particular directory then move this updated file to that particular directory.

If the file is not existed in any of the directories then place this file in a default directory.

1) I am getting the file
Code:
gds_daily.csv

2) File name has to be parameterized
Code:
file_name=$1

3) The file is existed in the directory
Code:
/home/data/gds/gds_daily.csv

4) then the latest file will be replaced in the directory
Code:
/home/data/gds/

5 )I am getting the file
Code:
sos_daily.csv

6) Search for this file in all directories and sub directories
and not found in any of the directories then move to the directory
Code:
 /home/def


Please help me.

Thanks

---------- Post updated 05-11-16 at 04:06 PM ---------- Previous update was 05-10-16 at 07:49 PM ----------

Hi All,

Please help me.

Thanks

Last edited by vbe; 05-11-2016 at 08:27 AM.. Reason: added x)
# 2  
Old 05-11-2016
Moderator's Comments:
Mod Comment No Bumping - Last warning!


What have you done so far? ( I numbered so we can discuss on part/from a value... )

Point 3 and 6 need to be more clear...

Last edited by vbe; 05-13-2016 at 08:28 AM.. Reason: oops typo
# 3  
Old 05-13-2016
Hi,

Please find the details.
3)
Let us say the input file is gds_daily.csv.
I have to search for this and the file is already existed in the below directory.
So I have replace the old file with new file
/home/data/gds/gds_daily.csv


6)
Let us say the input file is sos_daily.csv
Search for this file in all directories and sub directories
and not found in any of the directories then place the file sos_daily.csv in the directory
/home/def

Thanks.
# 4  
Old 05-16-2016
Hi Experts,

Could you please help me.

Thanks,
# 5  
Old 05-16-2016
I hardly understand that request. What if more than one file exist in the target directory branch? If
Code:
TGT=$(find /home/data -name $1)
[ -n "$TGT" ] && mv "$1" "$TGT" || mv "$1" "/home/def"

does NOT satisfy your request, rephrase it WAY more eloquently and precisely!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove directories when specific file is in directory?

Hello :) I need little help i have following cmd: this only able to delete files but not folder which contain that file find /home/test/* -name "*.testfile" -type f -exec rm -i {} \; how to delete whole directory if file called somethingblahblah.testfile is there? Thanks you :) (3 Replies)
Discussion started by: ZerO13
3 Replies

2. Shell Programming and Scripting

Command to Search a FILE for a STRING in multiple DIRECTORIES

Hi, Can someone please help me with a Command to Search a FILE for a STRING in multiple DIRECTORIES. I am searching for the VIP in HTTPD.CONF in multiple httpd instances. I am using find ./ -name "httpd.conf" | xargs grep 10.22.0.141 cut -d: -f3- | cut -d ' ' -f4 | sort | uniq -c ... (1 Reply)
Discussion started by: crosairs
1 Replies

3. UNIX for Dummies Questions & Answers

How to search for a file having a particular character in a particular place in a directory.?

Hi Guys, I want to search for a specific file in a directory which have a "b" letter as the 3rd character in the name of the file. For Example : /abc/efg/ldbjfblkj.sh /abc/efg/erublkd.sh /abc/efg/eibueora.sh /abc/efg/kfvnmnb.sh Since we have 2 files with "b" as a 3rd character in... (5 Replies)
Discussion started by: Pramod_009
5 Replies

4. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

5. Shell Programming and Scripting

Looping inside directories based on a file which contains file directory list

Hi All, Please help. I have got a file which contains a listing of a file and some directories after it, one by one. I am calling this file xyz.txt here file1 dir1 dir2 dir3 dir4 file2 dir5 dir6 dir7 dir8 file3 dir9 dir10 dir11 dir12 (6 Replies)
Discussion started by: Piyush Jakra
6 Replies

6. Shell Programming and Scripting

Search for file extensions in the given directories

Hey guys, I'm lost... I need to make a script that will work in this way: ./script.sh -e sh /usr/bin /home/student this script will result in this output: amuFormat.sh /usr/bin gettext.sh /urs/bin perfect.sh /home/student the parameter -e <ext> gives you which... (2 Replies)
Discussion started by: Miki1579
2 Replies

7. UNIX for Advanced & Expert Users

Search file in all directories.

Hi colleagues, I need to search one file in all dierctories, i have O.S. AIX 5.3, my file began with cc, the others caracters i unknow. Then i can to search one string in file in all dierctories. Thank you for advanced. (8 Replies)
Discussion started by: systemoper
8 Replies

8. UNIX and Linux Applications

Perl Script to read an excel file into an array and search in the UNIX directories

Hi, I want the Perl script with versions 5.8.2 and 5.8.5 starting with #!/usr/bin/perl The Perl program should read the excel file or text file line by line and taking into an array and search in the UNIX directories for reference file of .jsp or .js or .xsl with path .The Object names... (2 Replies)
Discussion started by: pasam
2 Replies

9. UNIX for Dummies Questions & Answers

using gsed with cp to sort files in directory - every N file copy to new place

Hi all, I'm having a problem with some basic piping issues... I have been able to get in a directory and ls | gsed in order to list every N file for instance: ls | gsed -n '2~5p' The thing is I want to be able to copy the output files to a new directory. Basically directory /all has a... (4 Replies)
Discussion started by: dgoss
4 Replies

10. UNIX for Dummies Questions & Answers

creating separate directories according to file extension and keeping file in different directory as

unix program to which a directory name will be passed as parameter. This directory will contain files with various extensions. This script will create directories with the names of the extention of the files and then put the files in the corresponding folder. All files which do not have any... (2 Replies)
Discussion started by: Deekay.p
2 Replies
Login or Register to Ask a Question