![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Adding Multiple Lines to Multiple Files | dayinthelife | Shell Programming and Scripting | 2 | 06-04-2008 12:50 PM |
| calculate average of multiple line data | smacherla | HP-UX | 4 | 05-23-2008 05:39 PM |
| script to find the average number or files? | bbbngowc | Shell Programming and Scripting | 2 | 03-27-2008 12:57 PM |
| grep throught Zip file. | deepakwins | UNIX for Dummies Questions & Answers | 1 | 01-30-2008 06:34 PM |
| find common elements in 2 files (for loop) | ibking | Shell Programming and Scripting | 4 | 12-11-2007 04:51 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Average of elements throught multiple files
Hi,
I got a lot of files looking like this: Code:
1 0.5 6 I want to build the average for every line, and write the result to a new file. The averaging should start at a specific line, here for example at line 380'000. Help is much appreciated... chillmaster PS: This should be done for data files of CFD calculations, exactly to average a transient calculation and read it with postprocessor again. So the first (here ard 380'000) lines are the coordinates of the field points following hereafter... |
|
||||
|
Hi jim,
yep, you are rite. Maybe i wrote a little confused, English isnt my mother tongue... Anyway, rite now I got 100 files each with 1'050'000 rows, just one column. Every file is a specific point of time. I want an average for each line over all the 100 files (Line 1 for all 100 files, Line 2 ...). However, I need to start averaging at a specific line, something ard 380'000. These first 380'000 rows are coordinate points. I think first I need to join the files, that I get one file with 1'050'000 rows and 100 columns. I tried: Code:
cut -f 1 data0050_1.ip data0055_1.ip | pr -2 -t > test.ip It seems that there is a limit for the lenght of the files... pressure 2 velocity 23 . 345 . . . . 2 . 3 pressure 6 . 5 . 64 . 64 3 6 Pressure is supposed to be the first row... Thank you for your help |
|
||||
|
Great. I got it. Try something like this.
Assume your files have the same base name with numbers after them 1 - 100 or so and the files are called filename1... filename<nnn> Code:
#!/bin/ksh
> outputfile
filecount=0
for file in filename*
do
sed -n '380000, $p' $file >> outputfile
filecount=$(( filecount + 1))
done
awk -v filecount=$filecount '
BEGIN { i=1}
{ avg[ i % 670000]+=$1 }
END{for (i=1; i<= 670000; i++) { printf("%.3f\n", avg[i]/filecount) }) ' outputfile > avgfile
|
|
||||
|
Hello jim,
thank you very much for your help. The first part is working, the second part brings a syntax error at awk line 3. Unfortunately, I dont know anything about awk. I will check the syntax in the next few days, since it seems to me very powerful. I would be very happy, if you could help me again anyway, because I think I need some time to get the awk usage... One more question about sorting the files: The first part makes a really big file, while I cant see at which position one file ends and the next is starting. Actually, you set an awk comand with the number 670'000, I think thats the file lenght of each seperate file in the big outpufile, is that rite? Anyway, do you know, how i can join multiple one column files to one multiple column file. Seems to me not to be a really difficult task, however, I cant find any helpful information. Thank you very much chillmaster |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|