The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 01-05-2009
npatwardhan npatwardhan is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 135
ok thanks that worked..
here is what i want to do next. i have this file called test which has values as follows:


Code:
1
2
3
4
5
6
7

i have another file called data with multiple fields and records as follows:
(there are more columns but following is just a snapshot of the file)


Code:
col1  col2
1       1.4
2       1.6
3       1.7
4       1.8
5       1.9
6       2.0

i would like to get a file with entries as follows: (i am subtracting each row from the data file for the first column from the first entry of the first row in the test file)


Code:
col1         col2
1-1         1.4-2
2-1         1.6-2
3-1         1.7-2
4-1         1.8-2
5-1         1.9-2
6-1         2.0-2

so far i was trying something along these lines:


Code:
awk 'NR==FNR{for(i=1;i<=NF;i++) {a[NR]=$i;next} {b[NR]=$i;next} END {for(i=1;i<=NF;i++) {printf("%1.11f, %1.11f\n",a[i],b[i])}}' test data > try

i am trying to save all the rows from the test file in an array(a). how do i save the col1 and col2 values from the data file in an array and then use it to subtract values from array(a)? i want to stick to awk.
thanks