bash - I want to extract data between sentences and send it to a file -


I have a time log file that starts with a statement:

  N: 5, image: 320 420, SF: 2  

then ..

  0.192 9.1829 879.08  

.. With the value of

is.

I want to remove the time (floating-point number) in a file for N = 5, then N = 10

< P> This is the code that I wrote

  strict use; Use warnings; #Open (FH, "Out_Put / Time_Log1TTT"); # My $ row = & lt; FH> # My @b = & lt; FH>; #Foreach My $ line (@b) # {# perl -i.bak -ne print until open / #} (FIL, "Out_pot / time_lag1.1"); My $ sum = 0; My $ count = 0; My $ average = 0; Foreign (& lt; FIL & gt;) {chomp; $ Sum + = $ _; $ Count ++;} $ average = $ amount / $ count; Close (fil); Print "yoga = $ sum \ n"; Print is "average = $ average \ n";  

OK, so given what you are trying to do - It seems that you summarize the prices after the 'N' line:

  Use strict; Use warnings; My% n_values; My% n_count; My $ current_n = 0; While (& lt; data & gt;) {chomp; If (m / \ AN: \ d + /) {($ current_n) = (m / \ AN: (\ d +) /); } My ($ value) = (m / ([\ d.] +) /); If (defined $ value) {$ n_values ​​{$ current_n} + = $ value; $ N_count {$ current_n} ++; }} Foreach My $ n (keys% n_values) {print "n: $ n value: $ n_values ​​{$ n} \ n"; } __DATA__ N: 5, Image: 320 420, SF: 2 0.192 9.1829 879.08 N: 100, Image 640 480 SF 2 0.98 56.973 230.988  

This through the contents of the data The cycle will be , one line reading at a time, and $ current_n starts each time it starts N: . A hash is updated to $ current_n , as long as there is a value to add to it.

What should be the trick, although this error does not do much in the way of the investigation such as invalid value in the file


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%? -