I have 11 directories with around 200 files in each. In each directory the files are labeled out.0 through out.201 . Each file has around 118 numbers in a single column. I need to sum the files in each directory so each directory will have a resultant vector that is 118 numbers long. I then need to combine the vectors into a single file that is 11*118 (1298) numbers long. Someone mentioned using 'cat' but since i only wrote my first csh script over the weekend I have no idea where to start.
you have the directory structure right. Im not trying to sum up each number within the file. Within each dir all 200 of the first entries would be summed, same for the second ..... through the 118th entry of each file. This would result in each directory having a summed column that is 118 numbers long. I then need to combine those numbers from each dir into one file so it would contain the 118 numbers * 11 dir = 1298 numbers in the final data file.
DirA
out.0
contains 118 rows, each with a number
out.1
contains 118 rows, each with a number
...
DirB
repeats
inside DirA
open out.0
add up all rows in the file, get a number 31543
write that to a temp file call DirA_sums
open out.1
add up all rows in the file, get a number 19548
write that to a temp file call DirA_sums
DirA_sums now contains 31543 19548
continue through all of the files
inside DirB
process the out.? files in same manner
continue through DirK (11th directory)
After the above, I would have eleven files, each containing 118 numbers (which are the sums from the files within the directory)
inside DirA
open out.0
store all rows in the file to array
open out.1
store all rows in the file to temparray
set array = array + temparray
open out.2
store all rows in the file to temparray
set array = array + temparray
continue through all of the files
Write array to tempfile out.DirA
inside DirB
process the out.0-200 files in same manner
continue through DirK (11th directory)
after 11th directory
Write out.DirA to finaloutput.file
append out.DirB to finaloutput.file
...
append out.DirK to finaloutput.file
given a sample structure (2 dirs, 4 files in each)
each file has five numbers in it, one per line
./DirA/out.0
./DirA/out.1
./DirA/out.2
./DirA/out.3
./DirB/out.0
./DirB/out.1
./DirB/out.2
./DirB/out.3