Linux shell scripting - Simple awk script issue -


I am trying to practice a very simple weird script and can not understand why this does not work is.

awk script, beginning with 2012 should only be used to display the entries, so that the input file:

  December 2009 X 29.44 December 2009 Y 32.32 January 2012 X 321.11 2012 February Y 1.99 2012 February X 32.9 9 2012 March x 11.45 January 2010 X 14.75 February 2011 y 21:00 March 2011 X 7.77  

The output should be as follows:

 % awk -f awkscriptfile 2012 for data inputfile ================= January: 321.11 February: 1.99 ft Re: 32.99 March 11.45 ============ is ======= volume for 2012: 367.54 4 records processed%  

However, I What to get:

 % awk -f year 2012 ============================== ==== data Inputfile Awkscriptfile December 2009 X 29.44 December 2009 Y 32.32 2012 January x 321.11 January: 321.11 February 2012 Y 1. February 99: 1.99 2012 February x 32.99 February: 32.99 2012 March x 11.45 March 11.45 in January 2010 X 14.75 2011 Feb Y 21.00 2011 March x 7.77 ======================== For the 2012 volume: $ Sum $ counts record resource Therefore, the strange script is obvious that it should be printing too much, and for some reason the yoga and counting variables are not being printed.   

This is the code for me awk script:

  BEGIN "print" data for 2012 "print" ======== ========================= "count = 0 sum = 0} $ 1 ~ / 2012 / {print $ 2,": ", $ 4 calculations + yoga + = $ 4} END {print "================================================================== = "Print" is the volume: $ sum "print" $ count records processed "}  

From everything I'm looking for reference, I see no reason why this code Should not work, hope someone else can tell me what I am doing.

  awk -vy = "2012" '$ 1 == y {one] = $ 2 ":" $ 4K + = $ 4, c ++} last {line = "==================="; Printf "year% s \ n% s \ n", y, data for line; For (i = 1; i & lt; = NR; i ++) if (a [i]) Print [i] printf "% s is \ nvolume% for s:% .2f \ n% d records processed \ N ", line, y, s, c} 'file  

with its data, it outputs:

  data for the year 2012 ========= ========== January 321.11 February: 1.99 11.45 for February: 32.99 in March 2012 ================= == Quantity: 367.54 4 Resource of Record  

Comments