finding, copying, assembling


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers finding, copying, assembling
# 1  
Old 02-11-2012
Question finding, copying, assembling

Hi everybody,

I've been running some analyses, the results of which have been stored in a sequential manner with a directory structure like step0, step1, step2, ... for iterations 0-2, for example. Each iteration contains several nested folders, with three pieces of information I need. I need to do the following:

(1) Find within each iteration directory, and extract sequentially to a new file, the number following the text, "final GAMMA-based Likelihood:" The numbers need to be in a list whose order preserves the original order (iteration 0, 1, 2, ...).

(2) Find, copy, and concatenate into a single file the contents of the file "RAxML_bestTree.default." As for (1), the order should preserve the iteration order.

(3) Copy the file "input.phy" to a new directory called alignments, preserving the order of the iterations, and renaming the file to correspond to the iteration number, e.g. input.phy.0, inpout.phy.1, etc.

I anticipate this will require some grep and for loops, but I am very much unsure of how to proceed.

Thanks!

~John
# 2  
Old 02-12-2012
hi, JDenton,

just to clarify the structure of the problem:

A. directories should be nested like the following?
Code:
/parent/directory/JDenton/
+--step0/
|  +--subdir0/
|  +--subdir1/
|  ...
|
+--step1/
|  +--subdir0/
|  +--subdir1/
|  ...
|
+--step2/
   +--subdir0/
   +--subdir1/
   ...

where information is actually stored in an unspecified number of files inside each step<N>subdir<M> directory; can we assume the files are ordered by filename in the order the information is to be searched and (if found) retrieved?
If this is the case, the command to list the files paths, keeping at the same time the alphabetical order of subdirs and filenames:
Code:
find JDenton/ -type f | sort

The output of the command should resemble something like this:
Code:
JDenton/step0/subdir0/file0
JDenton/step0/subdir0/file1
JDenton/step0/subdir0/file2
JDenton/step0/subdir1/file0
JDenton/step0/subdir1/file1
JDenton/step1/subdir0/file0
JDenton/step1/subdir0/file1
JDenton/step1/subdir0/file2
JDenton/step1/subdir1/file0
JDenton/step1/subdir1/file1
JDenton/step1/subdir2/file0
JDenton/step1/subdir2/file1
JDenton/step2/subdir0/file0
JDenton/step2/subdir0/file1
JDenton/step2/subdir0/file2
JDenton/step2/subdir1/file0
JDenton/step2/subdir2/file0
JDenton/step2/subdir2/file1
JDenton/step2/subdir3/file0
JDenton/step2/subdir3/file1
JDenton/step2/subdir3/file2

You see that the alphanumerical order is kept.

You may redirect the output of the above command to a file in order to keep it for reference during the current search and extraction job:
Code:
if [ -f /parent/directory/filelist.txt ] ; then
   rm -f /parent/directory/filelist.txt
fi
find JDenton/ -type f | sort >> /parent/directory/filelist.txt

I think this is the core of your task, having an alphanumerically ordered list of files.

B. once you have the alphabetically ordered list you may start to look for the entries "final GAMMA-based Likelihood:" in the files:
Code:
for currentfile in `cat /parent/directory/filelist.txt`
do
   #   assuming that the searched string appears in a single line 
   #   and that the number appears after the colon, 
   #   and that there is a single colon in the line
   egrep "final GAMMA-based Likelihood:" ${currentfile} | awk -F":" ' { print $2 } ' >> /parent/directory/GAMMA-numbers.txt
done

C. similar concept for your (2) bullet element:
Code:
for currentfile in `cat  /parent/directory/filelist.txt | egrep "RAxML_bestTree.default"`
do
   cat ${currentfile} >> /parent/directory/singlefile.txt
done

D. for bullet (3) task, you should be able to do it by yourself at this point =)

see ya
fra

Last edited by frappa; 02-12-2012 at 06:07 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Matching string and assembling

I have been thinking how to address this particular task but is way beyond my knowledge. I have a reference sequence, something like this: >Reference AGAGAGACCTGGAGAGAGAGTGACGATGAGCAGTGACGATGACGTACGATAGCAGTAGACGCA and a input.txt file with thousand of short sequences, something like this ... (4 Replies)
Discussion started by: Xterra
4 Replies

2. Shell Programming and Scripting

Need help in finding and copying list of files using bash shell script

Dear All, I have a situation where I want to copy some files of type .txt. These files are o/p from one program. Some of the files are named as fileName .txt instead of fileName.txt after fileName by mistake I have specified "space". Now I want to move these files as follows. mv fileName*... (13 Replies)
Discussion started by: linuxUser_
13 Replies

3. UNIX for Advanced & Expert Users

Challenges in finding and copying the block

Hi, I have a below challenging task where iam unable to find the block and copy the same into a file. I tried my luck,howver iam unable to reach the first and second step..Can anyone help me with a clue or with the commands so that i can give a try. 1. search the <number>9966993366</number>... (2 Replies)
Discussion started by: cskumar
2 Replies

4. Shell Programming and Scripting

Assembling the Pieces of a Regular Expression

Hello all. I'm scripting in ksh and trying to put together a regular expression. I think my logic is sound, but I'm doing the head-against-the-wall routine while trying to put the individual pieces together. Can anybody lend some suggestions to the below problem? I'm taking a date in the... (2 Replies)
Discussion started by: Michael_K
2 Replies

5. UNIX for Dummies Questions & Answers

Finding duplicates then copying, almost there, maybe?

Hi everyone. I'm trying to help my wife with a project, she has exported 200 images from many different folders, unfortunately there was a problem with the export and I need to find the master versions so that she doesn't have to go through and select them again. I need to: For each image in... (2 Replies)
Discussion started by: Rhinoskin
2 Replies

6. Shell Programming and Scripting

Finding & Copying files

Hello :) can someone please help me with this task: I am in the shell, in folder "Main" below the folder Main are sub folders: "sourceA", "Source B", and "target" in sourceA and source B are files, and in folder "Main" is a textfile, with filenames, one filename per line. I need a... (4 Replies)
Discussion started by: Y-T
4 Replies

7. UNIX for Dummies Questions & Answers

Finding and Copying Email

I have to create a bash script that will find Feedback emails and copy them to a labFeedback folder in my mail directory. I have an idea in my head on what commands can be used for this (find obviously among them). However, I have no idea where to start. I'm not sure what info needs to be given,... (1 Reply)
Discussion started by: Joesgrrrl
1 Replies

8. Shell Programming and Scripting

Help assembling script

I am trying to figure out how to write a bash script to process a file in order to make it more user readable. The file to be processed is quite uniform, every line starts with a 32 bit Unix timestamp in hexadecimal format, then a single tab charcter (0x09) then a string of text. What I want to... (1 Reply)
Discussion started by: stumpyuk
1 Replies

9. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

10. UNIX for Dummies Questions & Answers

finding and copying files !

Hi , I have a question relating to finding and copying files. i need to find the .pdf files from the specified directory which has subdirectories too. I only need .pdf files and not the directories and need to copy those files into my current directory. copy files from :... (5 Replies)
Discussion started by: bregoty
5 Replies
Login or Register to Ask a Question