I need to change a number in a file by adding some residuals respectively
To make it clear,
I need to add 0.11 to the number between 24-28 (which is below the SECON) for all the lines starting with FRR1
or I need to add 0.13 to the number between 24-28 (which is below the SECON) for all lines starting with FRR4
The values for the codes (FRR1, FRR4...) are constant.
since the columns are vary from line to line I try to set the characters between 24-28 so that the code would change only the second...
I tried this code but it is ofcourse useless
set SEC=`\cut -c 24-28 inp`
awk '{sub(" FRR2 * " $SEC," FRR2 * " $SEC+0.11)}1' inp > out
[/SIZE]
and here is the example of my file
2009 1024 0332 41.7 L 40.797 27.526 12.7 FRO 14 0.5 1.5LFRO 2.5CFRO 1.6LMAM1
GAP= 86 0.97 2.6 2.4 4.1 -0.3933E+00 -0.3282E+01 0.2834E+01E
STAT SP IPHASW D HRMM SECON CODA AMPLIT PERI AZIMU VELO AIN AR TRES W DIS CAZ7
FRR2 SZ IP 332 44.09 155 -0.4510 3.95 323
FRR1 SZ IP 332 46.23 123 0.6810 11.0 232
FRR1 SE ES 332 48.86 123 0.5310 11.0 232
YNKM SZ IPG 0 0332 45.82 169.7e+01 123 0.0110 11.4 286
YNKM SZ ESG 1 0332 48.03 1.6e+02 123 -0.74 7 11.4 286
MADM SZ IPG 0 0332 47.05 124.0e+01 99 0.0810 19.8 144
MADM SZ ESG 1 0332 49.98 6.6e+01 99 -0.80 7 19.8 144
FRR4 SZ IP 332 48.23 92 0.4210 26.3 104
FRR4 SE ES 332 51.63 92 -0.6110 26.3 104
SART SZ IP 0 0332 48.78 426.2e+00 91 -0.29 9 31.6 248
SART SZ ES 2 0332 53.66 1.6e+01 91 -0.75 5 31.6 248
2009 1025 0114 10.4 L 40.824 27.977 11.7 FRO 12 0.5 1.4LFRO 2.6CFRO 1.6LMAM1
GAP=103 1.23 3.6 3.0 5.2 -0.2501E+01 -0.3318E+01 0.5687E+01E
STAT SP IPHASW D HRMM SECON CODA AMPLIT PERI AZIMU VELO AIN AR TRES W DIS CAZ7
FRR4 SZ IP 114 15.03 110 0.3010 15.6 233
FRR4 SE ES 114 17.47 110 -0.4010 15.6 233
MARM SZ IPG 0 0114 15.18 183.9e+01 110 0.1910 15.9 355
MARM SZ ESG 1 0114 18.13 1.5e+02 110 -0.18 7 15.9 355
FRR2 SZ IP 114 18.57 72 -0.11 9 40.4 270
FRR2 SE ES 114 24.13 72 -0.57 9 40.4 270
FRR1 SZ IP 114 20.15 72 0.04 9 47.7 258
2009 1025 0304 42.0 L 40.814 27.754 11.7 FRO 14 0.6 1.6LFRO 2.7CFRO 1.8LMAM1
GAP=126 1.36 3.7 2.8 4.8 0.3033E+00 -0.2901E+01 -0.5029E+01E
STAT SP IPHASW D HRMM SECON CODA AMPLIT PERI AZIMU VELO AIN AR TRES W DIS CAZ7
FRR4 SZ IP 0304 46.22 125 0.6910 10.3 142
FRR4 SE ES 0304 48.07 125 -0.0110 10.3 142
MADM SZ IPG 0 0304 47.08 245.1e+01 106 -0.0510 19.3 203
MADM SZ ESG 1 0304 50.01 7.9e+01 106 -0.85 7 19.3 203
FRR2 SZ IP 304 47.29 102 0.1110 21.6 274
FRR2 SE ES 304 50.20 102 -0.7410 21.6 274
MARM SZ IP 0 0304 48.11 241.0e+02 100 0.1310 24.4 46
MARM SZ ES 3 0304 52.06 2.5e+02 100 -0.26 2 24.4 46
FRR1 SN IP 304 49.43 98 0.7410 29.2 253
FRR1 SE ES 304 53.13 98 -0.4210 29.2 253
$ cat addfr.awk ( with this line we see the content of the input file?)
and
$ awk -f addfr.awk data (this line writes the changes to data, the output file)
I am wrong?
---------- Post updated at 03:59 AM ---------- Previous update was at 03:27 AM ----------
I see that it is a little bit complicated I could not understand what is "p" for and when I run the script:
sezim@localhost#cat gauss.awk
awk '
{
for(i=1;i<=NF;i++) # for every field on every line
if($i~/[A-Z]{5}[0-9]$/){ # if a field contains a station number
getline p<f # then get the next noise correction
split(p,N) # split the fields of the noise correction into array N
sub($(i+1)+0,sprintf("%.3f",$(i+1)+N[2]),$(i+1)) # substitute the numerical value in the next field with the modified value
}
}
1 # print line
' f=noisedata # set variable f to noise file
sezim@localhost#awk -f gauss.awk mydata
awk: gauss.awk:1: awk '
awk: gauss.awk:1: ^ invalid char ''' in expression