Hi Monks,

I need ur help in solving this stuff. My req is ...

1. I have files SU1, SU2 ...like that . But the total number of files is unknown...there might be 7 or 6 files....

2. Similarly i have MU files -> MU1, MU2 etc...

3. These are tab delimited content. Each tab has Numbers..

Sample format is:
TextString1 \t 23.67 \t 57 \t 90.8 TextString2 \t 20.9 \t 58 \t 99
4. Now I have to collect only the 2nd column from each file and put under output file
5. Output header is:
Text String \t SU1 \t SU2....\t SU-Average \t MU1 \t MU2......\t MU-Av +erage TextString1 \t [value from Row 1 - Column 2 of SU1] \t [value from Row + 1 - Column 2 of SU2] \t [Avg of SU1 & SU2] ...like that
My approach is:
1. Read the contents and parse the 2column ..save it in Array..named @SU1 etc..
2. Then in a for loop ...print the rows in to a file
for(my $i = 0; $i < $total_lines_in_each_file; $i++){ print(OUTPUT "$TextString[$i]\t$su_first[$i]\t$su_second[$i]\t$su_thir +d[$i]\t$su_average\t$mu_first[$i]\t$mu_second[$i]\t$mu_third[$i]\t$mu +_average \n"); }
The output will be
Text String \t 57 \t 58 \t Avg(57,58)
My Problem:

1. Here the arrays SU_first etc are hardcoded. Ie I have restricted to only 3 arrays. If there are SU4 etc I cant use this script How to give a Dynamic name for array and retrieve it..?

2. Or any other better approach?!!!

Finally from n number of tab limited files take only the 2nd column, find the average of each row and print it in another file.

Pls help me. Thanks in advance!

(Original content above, restored by Arunbear. Updated content follows:)

Hi Thanks for the response..But I'm not able tomend it as per my req..(I need some more expertise in PERL) here is what I need..
su1_file 1 "abc" 6 8 "def" 7 9 "ghi" 2 5 su2_file 2 "abc" 60 8 "def" 70 900 "ghi" 20 5 su_file 3 "abc" 600 8 "def" 700 900 "ghi" 200 5 Output file: Header su_file1 su_file2 su_file3 average ...mu1_ mu2_ mu3_ etc.... abc 6 60 600 *** def 7 70 700 *** ghi 2 20 200 ***
so @su1 will have 6,7,2 @su2 will have 60,70,20 etc..But I dont know how many such files in mu and su..there might be Su9, su10 etc. Runtime I need to check the number of files, get those values and print to one single file. Once I parse the values from each file, i have to print the values in columnwise. I think the solution given by you does an average (some calculation) of all su values in column 1 .. Can u pls help me. ?? Now I have hard coded the number of files to only 3 in my code.

In reply to Parse values from multiple files into one by hiradhu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.