to parse (or grep) a number from a datafile and write it to tab limited file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to parse (or grep) a number from a datafile and write it to tab limited file
# 1  
Old 03-15-2010
to parse (or grep) a number from a datafile and write it to tab limited file

Hi All,
I have a folder that contain 100's of subfolders namely:
Code:
Main folder -> GHFG
  - Subfoders ->10 
                        100
                        234
                        102
                        345
                        ..
                        ..
                        ..
                        100's of folders

Note that each subfolder have a number as name.

Within each subfolder there are 3 files named associated with the subfolder name but different extensions.

Code:
For Example:
In the subfolder 100: there are 3 files->100.txt, 100.out and 100.log

What I need is to grep (parse) a data (numberical) value from the .log file and then print this value in a tab delimited file in the main folder in the following way:

Code:
            10 3456 (value greped)
                       100 567
                        234 56
                        102 678
                        345 6789

Following is an example of a log file
Code:
sizeof(size_t) = 8 bytes


      224 bytes for distance
   221552 bytes for conP
     7264 bytes for fhK
  5000000 bytes for space

2 branch types are in tree. Stop if wrong.
TREE #  1
(((7, 2), ((((3, 4), 5), 6), 8)), 1);   MP score: 416
This is a rooted tree, without clock.  Check.

  3101728 bytes for conP, adjusted

ntime & nrate & np:    14     2    18
branch=0  freq=0.702014 w0 = 0.283251
branch=0  freq=0.297986 w1 = 1.000000
                        Qfactor for branch 0 = 7.296155
branch=1  freq=0.560244 w0 = 0.283251
branch=1  freq=0.237809 w1 = 1.000000
branch=1  freq=0.201947 w2 = 1.000000
                        Qfactor for branch 1 = 6.472120
w[0] = 0.283251
w[1] = 1.000000
w[2] = 1.000000
Out..
lnL  = -4436.816826
1133 lfun, 9064 EigenQcodon, 67400 P(t)
end of tree file.

Time used:  2:05

What I need to grep is highlighted with bold font (lnL = -4436.816826)

I need to have the numerical value, -4436.816826 parsed out and printed to a file along with the first part of folder name.

Please let me know the best way to do this in sed or awk.

LA
# 2  
Old 03-15-2010
something like;

Code:
for file in $(find . -name "*.log" -type f 2>/dev/null)
do
filename=$(basename $file)
filepart=${filename%\.*}
value=$(grep '^lnL' $file | awk -F "[ ]*=[ ]*" '{print $2}')
printf "%s\t%s\n" $filepart $value
done

# 3  
Old 03-15-2010
Thanks..it worked
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep solutions tab-delimited file

Hello, I am trying to find a solution to problem that's proving to be beyond my newbie skills. The below files comes from a genetics study. File 1 describes a position on the genome and file 2 does the same but is formatted differently and has more information. I am trying to match all lines in... (5 Replies)
Discussion started by: andmal
5 Replies

2. UNIX for Beginners Questions & Answers

awk to parse current and next row in tab-delimited file

Hi there, I would like to use awk to reformat a tab-delimited file containing three columns as follows: Data file: sample 1 173 sample 269 530 sample 687 733 sample 1699 1779 Desired output file: sample 174..265, 531..686, 734..1698 I need the value... (5 Replies)
Discussion started by: emiley
5 Replies

3. UNIX for Dummies Questions & Answers

Replace period in a tab delimited file to a number

I have a file like this. It is tab delimited. Unfortunately, the missing data was filled in with a period "." (see the leading lines 1-5 columns) I want to substitute the periods for misisng data with an integer "-999". however, I do not want the global replace to change the other periods seen... (7 Replies)
Discussion started by: genehunter
7 Replies

4. Programming

How to write a java program that will parse through an XML file and generate a report?

I'm pretty new to Java and I am trying to write a program that will pick up a file from a windows directory adn parse through the XML file to produce a report that will show a total item count and a total paid amount. Any one have any suggestions? Trying to figure out where to start... (4 Replies)
Discussion started by: risarose87
4 Replies

5. Shell Programming and Scripting

Parse tab delimited file, check condition and delete row

I am fairly new to programming and trying to resolve this problem. I have the file like this. CHROM POS REF ALT 10_sample.bam 11_sample.bam 12_sample.bam 13_sample.bam 14_sample.bam 15_sample.bam 16_sample.bam tg93 77 T C T T T T T tg93 79 ... (4 Replies)
Discussion started by: empyrean
4 Replies

6. Shell Programming and Scripting

sorting the datafile in an order given in second datafile

Hi, I have two files: first input file is having 7-8 columns, and second data file is like I want to arrange my datafile1 in the order given in second data file, by comparing the seconddatafile with the second column of first file and print the entire line....also if any... (2 Replies)
Discussion started by: CAch
2 Replies

7. UNIX for Advanced & Expert Users

Problem while counting number of fields in TAB delimited file

I'm facing a strange problem, please help me out. Here we go. I want to count number of fields in particular file. filename and delimiter character will be passed through parameter. On command prompt if i type following i get 27 as output (which is correct) cat customer.dat | head -1 | awk... (12 Replies)
Discussion started by: vikanna
12 Replies

8. Shell Programming and Scripting

Copy and Paste Columns in a Tab-Limited Text file

I have this text file with a very large number of columns (10,000+) and I want to move the first column to the position of the six column so that the text file looks like this: Before cutting and pasting ID Family Mother Father Trait Phenotype aaa bbb ... (5 Replies)
Discussion started by: evelibertine
5 Replies

9. Shell Programming and Scripting

parse file into tab separated columns

Hello, I am trying to parse a file that resembles the last three groupings into something looking like the first two lines. I've fiddled with sed and awk a bit, but can't get anything to work properly. I need them separated by some delimiter. The file is some 23,000 lines of the stuff.... ... (9 Replies)
Discussion started by: dkozel
9 Replies

10. Shell Programming and Scripting

Combine a datafile with Master datafile, emergent!

Hi guys, my supervisor has asked me to solve the problem in 7 days, I've taken 3 days to think about it but couldn't figure out any idea. Please give me some thoughts with the following problem, I have index.database that has only index date: 1994 1995 1996 1997 1998 1999 I have... (6 Replies)
Discussion started by: onthetopo
6 Replies
Login or Register to Ask a Question