csv - AWK wrong math on first line only -


This input file is input.awk dos type

  06-13-2014, 08 : 43: 11 RLS 007817 RRC 001021 Yes, 71.61673,0,150,37,1 No., 11,156,1.35,306.418 4,3, -1,2.5165,20, -1.4204 -4,0,11,0,0,0, 0,0 1.00 e -001,0.2,3.00 e -001,0.6786031,0.5,6.37 e Ll0,40,30,222,200 -002, -539 L20,50,35,2l5,220, L30,60,40,207,240 -547, -553 L40,70 , 45196260, L50,80,50,l84,280 -560, -566 L60,90,55,l70,300, L70,l00,60,l57,320 -573, -578 L80,ll0,65,l4l,340, L90,l20,70,l26,360 -582, -586 200,l30,75,ll0,380, -590  < / Pre> 

This is basically necessary: ​​

  • Ignore the first 8 lines (OK)
  • 6,7 and selecting numbers on lines and Split;
  • Make AWK math on the column (only error in first line?)

Bash code

  #! / Bin / bash myfile = "input.awk" vzeros = $ (sed '6q; D' $ myfile) vshift = $ (but '7q; D' $ myfile) vcalib = $ (but '8q; D' $ myfile) IFS = ',' Read-a-Avis & lt; & Lt; & Lt; "$ {Vzeros}" read-A AVS & lt; & Lt; & Lt; Read "$ {Vshift}" -a avc & lt; & Lt; & Lt; "$ {Vcalib}" z1 = $ {avz [0]}; S1 = $ {AVIIS [0]}; C1 = $ {AVC [0]} z2 = $ {avis [1]}; S2 = $ {avance [1]}; C2 = $ {abc [1]} z3 = $ {avis [2]}; S3 = $ {AVS [2]}; C3 = $ {AVC [2]} G4 = $ Avis [4]}; S4 = $ {avs [4]}; C4 = $ {AVC [4]} # A variable will be sent to awk awk -v z1 = "$ z1" -v c1 = "$ c1" -v S1 = "$ s1" -v z2 = "$ z2 "-v c2 =" $ c2 "-v s2 =" $ s2 "-v z3 =" $ z3 "-v c3 =" $ c3 "-v s3 =" $ S3 "-v z4 =" $ z4 " -v c4 = "$ c4" -v s4 = "$ s4" 'nr & gt; 8 {FS = ","; Nc1 = c1 * ($ 1 - z1 - s1); Nc2 = c2 * ($ 2 - z2 - s2); NC3 = C3 * ($ 3 - G3 - S3); NC 4 = C4 * ($ 5 - z4 - s4); Print nc1, nc2, nc3, nc4} '$ myfile & gt; Test.plot  

This file is the result on test.plot

  11 -0.6 -3 -10 12 9.4 7.5 100 13 11.4 9 110 14 13.4 10.5 120 15 15.4 12 130 16 17.4 13.5 140 17 19.4 15 150 18 21.4 16.5 160 19 23.4 18 170 20 25.4 19.5 180  

This weird part is ... Only in the first line And after the first column all is wrong. .. and I do not know why this is the expected result file:

  11 7.4 6 90 12 9.4 7.5 100 13 11.4 9 110 14 13.4 10.5 120 15 15 14 12 130 16 17.4 13.5 140 17 19.4 15 150 18 21.4 16.5 160 19 23.4 18 170 20 25.4 19.5 180 I have highlighted the factors of improvement which are line 6,7 & amp; 8 And everything is fine.  

OS: Slackware 13.37

AWK: GNU Oak 3.1.6 Copyright (c) 1989, 1991 - 2007 Free Software Foundation.

I agree with @Ageian RJC

I have written your file and script to my On the machine copied and reduced it to processing on the first 2 lines of your data.

with your code, I do result in duplicate, ie

  #dbg $ 0 = 110,40,30,222,200, -539 #dbg c2 = 0.2 $ 2 = Z2 = 3 s2 = 0 11 -0.6 -3 -10 #dbg $ 0 = L20,50,35,2l5,220, -547 #dbg C2 = 0.2 $ 2 = Z2 = 3 s2 = 0 12 -0.6 -3 -10  

with FS = ","; Commented, and added to the -F, options list is the output you are looking for.

  #dbg $ 0 = 110,40,30,222,200, -539 # Dibiji C 2 = 0.2 $ 2 = 40 z2 = 3 s2 = 0 11 7.4 6 90 #dbg $ 0 = 120, 50,35,215,220, -547 # DBG C2 = 0.2 $ 2 = 50 z2 = 3 s2 = 0 12 9.4 7.5 100  

So make sure you enter FS from the block of code = ","; is extracted, and you are using -F, , in any case, I would say, that for every line that is being processed, FS = "," < / Code> Reset is not useful.

If it still does not solve, try the correct code on the machine with the new version of awk.


The first 8 records (when reading through FS = "[[space:]] what is happening to it, to fully describe it For the first line that completes your rule NR & gt; 8 , the transition to FS is still [: space:] when reading the field Then, FS is set to , , but this first line is not rescanned.

IHTH!


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -