Home > OS >  Shell script - from a text extraction by cyclic 1, 2, 3... Column data repeat replace the specified
Shell script - from a text extraction by cyclic 1, 2, 3... Column data repeat replace the specified

Time:10-08

Shell script, I wrote a cycle, want to use text a.t xt in the first line number 4, in turn, repeat. Replace TBCxiug dat file 2 of 1530.00, 74 lines of the script is as follows:
#!/bin/sh
B=1;
While [$b - lt 5];
Do
Echo $b;
Sed -i "s/` cat TBCxiug dat | awk '{print $2}' | awk 'NR 74=={print}' `/` cat a.t xt | awk '{print $b} | awk' NR==1 {print} '`/g "TBCxiug. Dat
B=` expr $b + 1 `;
The done

Text a.t xt content is as follows:
E+003 e+003 e+003 1.382734131 1.389259766 1.396336670 1.378035278 e+003
E+003 e+003 e+003 1.359675781 1.362385010 1.367266602 1.359435425 e+003
E+003 e+003 e+003 1.380192505 1.373034912 1.366114014 1.388231079 e+003

TBCxiug. Dat part content is as follows:
69 * DEFINE T
70 * DESCRIPTION
71 * END DESCRIPTION
72 * the PARAMETERS
The TYPE 73 NORMAL
74 MEAN 1530.00
75 STDEV 30.0000
76 * END PARAMETERS
77 * END DEFINE T
But the result seems to write a number, but the whole line count, are written in, as follows:
Results of cycle 1 time
* DEFINE T
* the DESCRIPTION
* END DESCRIPTION
* the PARAMETERS
TYPE NORMAL
MEAN e+003 e+003 e+003 e+003 1.378035278 1.382734131 1.389259766 1.396336670
STDEV 30.0000
* END PARAMETERS
* END of DEFINE T
The result of cycle 4
* DEFINE T
* the DESCRIPTION
* END DESCRIPTION
* the PARAMETERS
TYPE NORMAL
MEAN e+003 e+003 e+003 e+003 1.378035278 1.382734131 1.389259766 1.396336670
1.389259766 e+003 e+003 1.382734131 1.378035278 e+003
1.389259766 e+003 e+003 1.382734131 1.378035278 e+003
1.389259766 e+003 e+003 1.382734131 1.378035278 e+003

STDEV 30.0000
* END PARAMETERS
Later I change the red part of the script to awk "{print \ $$b}", the result form looks right, but to write the data is not present in the a.t xt TBCxiug data, don't know where come of, and each time you run the same script, written by numerical also is not the same! As follows:
* END DESCRIPTION
* the PARAMETERS
TYPE NORMAL
MEAN 56870
STDEV 30.0000
* END PARAMETERS
* END of DEFINE T
Pray god to analyze reasons and how to fix it! Thank you very much!