Sponsored Content
Top Forums UNIX for Dummies Questions & Answers move files that match specific conditions Post 302720545 by ada1983 on Wednesday 24th of October 2012 11:21:30 AM
Old 10-24-2012
move files that match specific conditions

Hi all,

I'm new to this forum and bash scripting. I have the following problem, I need to copy some files (from one dir. to another) whose first 5 numbers (subjects' ID) match the directory names. Here a shortened version of what I'm trying to do:

names=(32983_f 35416_f 43579_f) # these are the names of directories where I want to copy the files to

for i in ${names[@]}
do


if [$i = /Users/name/Dropbox/$i_exp.txt]; then

# _exp.txt is the constant part of the files I want to move

cp /Users/name/Dropbox/$i_exp.txt

/Users/name/Desktop/SUBJ/$i
# I want that this file is copied in the corresponding directory (with the same initial 5 numbers as the file)

fi
done


I hope it's clear. Like this obviously doesn't work it says

cp.sh: line 6: [32983_f: command not found,

Could you help me?
Best

Ada

Last edited by ada1983; 10-24-2012 at 12:29 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep'ing for specific directories, and using the output to move files

Hello, this is probably another really simple tasks for most of you gurus, however I am trying to make a script which takes an input, greps a specific file for that input, prints back to screen the results (which are directory names) and then be able to use the directory names to move files.... (1 Reply)
Discussion started by: JayC89
1 Replies

2. Shell Programming and Scripting

Find files that do not match specific patterns

Hi all, I have been searching online to find the answer for getting a list of files that do not match certain criteria but have been unsuccessful. I have a directory that has many jpg files. What I need to do is get a list of the files that do not match both of the following patterns (I have... (21 Replies)
Discussion started by: nikos-koutax
21 Replies

3. Shell Programming and Scripting

Recursively move directories along with files/specific files

I would like to transfer all files ending with .log from /tmp and to /tmp/archive (using find ) The directory structure looks like :- /tmp a.log b.log c.log /abcd d.log e.log When I tried the following command , it movies all the log files... (8 Replies)
Discussion started by: frintocf
8 Replies

4. Shell Programming and Scripting

How to match the below conditions?

Hello All, I have 2 files with around 2k records.. I am lost how to build a script to create another file with the below:confused::eek: Match Condition1: File1's 12th Columns data should exact match with File2's 19th Column's data Match Condition2: File1's 28th Column's data format is... (12 Replies)
Discussion started by: ailnilanjan
12 Replies

5. Shell Programming and Scripting

Bash to move specific files from folders in find file

I have a directory /home/cmccabe/nfs/exportedReports that contains multiple folders in it. The find writes the name of each folder to out.txt. A new directory is then created in a new location /home/cmccabe/Desktop/NGS/API, named with the date. What I am trying to do, unsuccessfully at the moment,... (7 Replies)
Discussion started by: cmccabe
7 Replies

6. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies

7. Shell Programming and Scripting

Insert a newline after match in files of specific name under some subdirectories?

Hi I'd like to add the newline: \tuser: nobody", or "<TAB>user: nobody to all files named: docker-compose.ymlin subfolders of pwd with names beginning with 10-20. Within these files, I'd like to find the line (there'll only be one) containing: command: celery workerNOTE: As far as... (2 Replies)
Discussion started by: duncanbetts
2 Replies

8. Shell Programming and Scripting

awk to print fields that match using conditions and a default value for non-matching in two files

Trying to use awk to match the contents of each line in file1 with $5 in file2. Both files are tab-delimited and there may be a space or special character in the name being matched in file2, for example in file1 the name is BRCA1 but in file2 the name is BRCA 1 or in file1 name is BCR but in file2... (6 Replies)
Discussion started by: cmccabe
6 Replies

9. Shell Programming and Scripting

Bash to move specific files to directory based on match to file

I am trying to mv each of the .vcf files in the variants folder to the folder in /home/cmccabe/f2 that the .vcf id is found in file. $2 in file will always have the id of a .vcf in the variants folder. The line in blue staring with R_2019 in file up to the -v5.6 will always be an exact match to a... (4 Replies)
Discussion started by: cmccabe
4 Replies

10. UNIX for Beginners Questions & Answers

Move several files into specific directories with a loop

Hello, I'm a first time poster looking for help in scripting a task in my daily routine. I am new in unix but i am attracted to its use as a mac user. Bear with me... I have several files (20) that I manually drag via the mouse into several named directories over a network. I've used rsync... (14 Replies)
Discussion started by: SonnyClark
14 Replies
Dist::Zilla::Plugin::FileFinder::ByName(3pm)		User Contributed Perl Documentation	      Dist::Zilla::Plugin::FileFinder::ByName(3pm)

NAME
Dist::Zilla::Plugin::FileFinder::ByName - FileFinder matching on pathnames VERSION
version 4.300020 SYNOPSIS
In your dist.ini: [FileFinder::ByName / MyFiles] dir = bin ; look in the bin/ directory dir = lib ; and the lib/ directory file = *.pl ; for .pl files match = .pm$ ; and for .pm files skip = ignore ; that don't have "ignore" in the path DESCRIPTION
FileFinder::ByName is a FileFinder that selects files by matching the criteria you specify against the pathname. There are three types of criteria you can use. "dir" limits the search to a particular directory. "match" is a regular expression that must match the pathname. "skip" is a regular expression that must not match the pathname. Each key can be specified multiple times. Multiple occurrences of the same key are ORed together. Different keys are ANDed together. That means that to be selected, a file must be located in one of the "dir"s, must match one of the "match" regexs, and must not match any of the "skip" regexs. Note that "file" and "match" are considered to be the same key. They're just different ways to write a regex that the pathname must match. Omitting a particular key means that criterion will not apply to the search. Omitting all keys will select every file in your dist. Note: If you need to OR different types of criteria, then use more than one instance of FileFinder::ByName. A FileFinderUser should allow you to specify more than one FileFinder to use. ATTRIBUTES
dir The file must be located in one of the specified directories (relative to the root directory of the dist). file The filename must match one of the specified patterns (which are converted to regexs using Text::Glob and combined with any "match" rules). match The pathname must match one of these regular expressions. skip The pathname must not match any of these regular expressions. CREDITS
This plugin was originally contributed by Christopher J. Madsen. AUTHOR
Ricardo SIGNES <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Ricardo SIGNES. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-21 Dist::Zilla::Plugin::FileFinder::ByName(3pm)
All times are GMT -4. The time now is 07:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy