How to copy specific files when you don't know the file name?
I hope this isn't as silly as it sounds from the title of the thread.
I have software that outputs files where the name starts with a real number followed by underscore as a prefix to an input file name. These will list in the directory with the file with the smallest real number prefix as the second file in the directory (there is another file that starts with 00).
Example directory,
I need a way to copy just the second and third file from a bash script, but, of course, I don't know exactly what the file names will be since they will be different every time the software runs.
In this case I need to identify the files,
and copy them to a different directory.
I suppose there is a way to read in all the file names and grab the real number into a variable, sort the variables, and then I would know the number that all the file names start with in order of the real, but I really don't know how to do that sort of thing. If there is a simple way to create a list (like [ ] I think) and then just be able to copy the first three files in the list, that would work fine. I can always delete the 00_ file, even though that is not a very slick solution.
Thanks for the help,
LMHmedchem
Last edited by radoulov; 12-10-2010 at 12:49 PM..
Reason: Code tags, please!
Now I need to read in the file names and capture some of the file name to a bash variable.
In the filename,
41.15_E2400_49.62_E200_2_ri_OA_f0_S4-A_37.20.1_1_ON_0.25lr_37.20.1.out.txt
I need to grab the E2400, E200, and the value 2 (_2_). I will start looking this up, but if someone knows off hand what to do, it would save allot of time. This kind of looks like a job for a tokenizer, if "_" can be used as the delimiter.
---------- Post updated 04-18-11 at 12:16 AM ---------- Previous update was 04-17-11 at 08:14 PM ----------
I have this,
which read the file names in a directory,
41.15_E2400_49.62_E200_2_ri.txt
42.38_E1600_52.12_E200_12_ri.txt
grabs the values I need and assigns them to some shell vars.
2
2400
2300
12
1600
1500
I don't know if the sed command there is the best way to get rid of the "E" or not. I also don't know if both vars can be assigned from a single awk command. I would be interested in knowing the perl version of what is above.
Is it possible to only copy selected files+its directories when you are copying recursively?
find /OriginalFolder/* -type -d \{ -mtime 1 -o -mtime 2 \ } -exec cp -R {} /CopyTo/'hostname'__CopyTo/ \; -print
From the above line, I want to only copy *txt and *ini files from /OriginalFolder/*
... (4 Replies)
Hello All,
Since i'm relatively new in shell script need your guidance.
I'm copying files manually based on a specific word in a file name and its extension and then moving it into some destination folder.
so if filename contains hyr word and it has .md and .db extension; it will move to TUM/HYR... (13 Replies)
I have to copy a particular file present in a main folder having part of the file-name present in many sub-folders to a new destination preserving the name of the source "part of the main folder" and previous file-name of the output file:
Example:
From /005_0/1000/005.xxx ->... (7 Replies)
Hi
I need to copy a huge directory with thousands of files onto another directory but without *.WMV files (and without *.wmv - perhaps we need to use *.).
Pls advise how can I do that.
Thanks (17 Replies)
Hi all:
Here's my dilemma: to identify files of a specific type, copy them to a new location while preserving the original file attributes (date, time, full path, etc), and at the same time capture the count of the number of files identified as a variable for later reporting.
Here's where I... (9 Replies)
hye there...
i have a problem to copy file in specific folder
that will change the name according to
host,time(%m%s) and date(%Y%M%D)
example folder name:
host_20100531.154101801
this folder name will always change...
but i just want to copy the AAA.txt and BBB.txt file..
really need... (17 Replies)
Hi all
I need to copy the entire contents of one file into an existing file at a specific location. I know the exact line number where I need to put it. It appears I would use either sed or awk to do this, but I have been unsuccessful so far:
File A
line 1
line 2
line 3
line 4
... (6 Replies)
Hi
I am a shell-script newbie and am looking to synchronize certain files in two directory structures.
Both these directory-trees are in CVS and so I dont want the CVS directory to be copied over.
I want only .sh and .pl files in each subdirectory under these directory trees to be... (3 Replies)