Hello again,
I've run into another problem that I've been unable to solve. With everyone's help last time, the script worked perfectly! This problem takes a little more finesse, and the bash script I thought up didn't work, so I've canned it. I'd like to try awk if possible. Here's my problem:
I have a multitude of sequential files like:
a_r01.dat
a_r02.dat
a_r03.dat
a_r04.dat
That continues to a certain number (in this case 47 of these .dat files, so the last one is _r47.dat). Inside of each file, there are four columns:
.705 0.00 1.00 0
1.02 0.00 1.00 10
2.05 0.00 1.00 100
3.06 0.00 1.00 5000
Here's the tricky part. The first column in each of the .dat files is the same, and I don't really care about the second or third column. What I would like is a script that looks at a_r02.dat and a_r01.dat, computes the different in the fourth column between the two files, and prints that (along with the value of the first column) into a different file, and then continues by computing the difference of the fourth column between a_r03.dat and a_r02.dat and prints that out. I'm not sure if I've explained this well, so I'll try for an example. Suppose two files are:
a_r01.dat
.705 0.00 1.00 10
1.02 0.00 1.00 10
2.05 0.00 1.00 15
3.06 0.00 1.00 35
a_r02.dat
.705 0.00 1.00 10
1.02 0.00 1.00 20
2.05 0.00 1.00 25
3.06 0.00 1.00 60
The script should compute the difference between the fourth column of each row and print an output.dat file that looks like:
.705 0
1.02 10
2.05 15
3.06 20
After it is done, it should continue by computing the same thing for a_r03 and a_r02, all the way down the line (until it terminates after running out of files), and each time, should put the difference in a new column in the output.dat file. So after a time, the output.dat should look like (using only column headers divided by a | symbol):
Column1 | r02-r01 | r03-r02 | r04-r03 | r05-r04 |
If my math is right, if I have 10 .dat files, the output.dat should have the first column and then 9 other columns of 4th row differences (between the input .dat files).
I hope I've explained this appropriately, and please let me know if anyone has any questions. I'm hoping that awk can do this, but if it is easier using perl or bash (or any other program), please let me know and I can easily get access to it. Thank you so much for your help!
