title: AWK - how to find unique vaulues and print first and last occurance
body: <p>I have a large text file which has multiple lines of data relating to one item, an item can have upto 15 different lines but all linked by a field called "itemId" i.e. itemId=&lt;12560317> each line has a timestamp at the beginning i.e. 170209 035711 0792.</p>
  
  <pre><code>170209 035711 0638 DE(N) ItemHandler.ItemLog event=&lt;DESTINATION_REPLY&gt;, *********************, itemId=&lt;12560284&gt;, globalId=&lt;12560284&gt;, cmcIndex=&lt;728&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForDestination&gt;, ccReason=&lt;SCANNER_DATA_ADDED&gt;, 
  170209 035711 0638 DE(N) ItemHandler.ItemLog event=&lt;REDIRECT_ITEM&gt;, *************************, itemId=&lt;12560284&gt;, globalId=&lt;12560284&gt;, cmcIndex=&lt;728&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForDestination&gt;, PendingchuteGroup=&lt;[3000]: Parked0&gt;, Pendingstrategy=&lt;notSpecified&gt;, CscdestinationId=&lt;-1: UnDef&gt;, CmcdestinationId=&lt;4099: All Scanners&gt;, position=&lt;sorter#0.scanner#4000: SCAN01&gt;, itemRevisionNumber=&lt;7&gt; ##[
  170209 035711 0715 DE(N) ItemHandler.ItemLog event=&lt;SCANNER_RESULT&gt;, ************************, itemId=&lt;12560311&gt;, globalId=&lt;12560311&gt;, cmcIndex=&lt;755&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForData&gt;, barcodeCount=&lt;4&gt;
  170209 035711 0715 DE(N) ItemHandler.ItemLog event=&lt;DESTINATION_REQUEST&gt;, *******************, itemId=&lt;12560311&gt;, globalId=&lt;12560311&gt;, cmcIndex=&lt;755&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForData&gt;, barcodes=&lt;[ProxyWrapperBarcode(barcode=&lt;JJD014600001372909310&gt;,
  170209 035711 0717 DE(N) ItemHandler.ItemLog event=&lt;DISCHARGE_ATTEMPTED&gt;, *******************, itemId=&lt;12560209&gt;, globalId=&lt;12560209&gt;, cmcIndex=&lt;653&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: ProjectHeadingForChute&gt;, CscdestinationId=&lt;19: CHU208&gt;, chuteGroup=&lt;[17, 19, 21]: [CHU207, CHU208, CHU209]&gt;, CmcdestinationId=&lt;19: CHU208&gt;, position=&lt;sorter#0: MS01&gt;, itemRevisionNumber=&lt;16&gt; ##[
  170209 035711 0719 DE(N) ItemHandler.ItemLog event=&lt;DESTINATION_REPLY&gt;, *********************, itemId=&lt;12560311&gt;, globalId=&lt;12560311&gt;, cmcIndex=&lt;755&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForDestination&gt;, ccReason=&lt;SCANNER_DATA_ADDED&gt;, PendingccResult=&lt;OK&gt;, Pendingstrategy=&lt;notSpecified&gt;,
  170209 035711 0719 DE(N) ItemHandler.ItemLog event=&lt;REDIRECT_ITEM&gt;, *************************, itemId=&lt;12560311&gt;, globalId=&lt;12560311&gt;, cmcIndex=&lt;755&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForDestination&gt;, PendingchuteGroup=&lt;[3000]: Parked0&gt;, Pendingstrategy=&lt;notSpecified&gt;, CscdestinationId=&lt;-1: UnDef&gt;, CmcdestinationId=&lt;-1: UnDef&gt;, position=&lt;sorter#0.scanner#4001: IU04-SCAN02&gt;, itemRevisionNumber=&lt;4&gt; ##[
  170209 035711 0792 DE(N) ItemHandler.ItemLog event=&lt;ITEM_AT_INDUCTION&gt;, *********************, itemId=&lt;12560317&gt;, globalId=&lt;12560317&gt;, cmcIndex=&lt;761&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: ProjectIdle&gt;, inductionId=&lt;3: IU04&gt;, position=&lt;sorter#0.induction#3: IU04&gt;, itemRevisionNumber=&lt;0&gt; ##[
  170209 035711 0792 DE(N) ItemHandler.ItemLog event=&lt;SET_ITEM_ID&gt;, ***************************, itemId=&lt;12560317&gt;, globalId=&lt;12560317&gt;, cmcIndex=&lt;761&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: ProjectIdle&gt;, itemRevisionNumber=&lt;0&gt; ##[
  170209 035711 0794 DE(N) ItemHandler.ItemLog event=&lt;REDIRECT_ITEM_REPLY&gt;, *******************, itemId=&lt;12560284&gt;, globalId=&lt;12560284&gt;, cmcIndex=&lt;728&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForDestination&gt;, CscdestinationId=&lt;3000: Parked0&gt;, chuteGroup=&lt;[3000]: Parked0&gt;, CmcdestinationId=&lt;3000: Parked0&gt;, position=&lt;sorter#0.scanner#4000: SCAN01&gt;, chuteListStartPoint=&lt;-1&gt;, itemRevisionNumber=&lt;9&gt; ##[
  170209 035711 0795 DE(N) ItemHandler.ItemLog event=&lt;RECONVERT&gt;, *****************************, itemId=&lt;12560284&gt;, globalId=&lt;12560284&gt;, cmcIndex=&lt;728&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForData&gt;, CscdestinationId=&lt;3000: Parked0&gt;, chuteGroup=&lt;[3000]: Parked0&gt;, CmcdestinationId=&lt;3000: Parked0&gt;, position=&lt;sorter#0.scanner#4000: SCAN01&gt;, chuteListStartPoint=&lt;-1&gt;, itemRevisionNumber=&lt;10&gt; ##[
  170209 035711 0795 DE(N) ItemHandler.ItemLog event=&lt;DESTINATION_REQUEST&gt;, *******************, itemId=&lt;12560284&gt;, globalId=&lt;12560284&gt;, cmcIndex=&lt;728&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForData&gt;, barcodes=&lt;[ProxyWrapperBarcode(barcode=&lt;JJD014600004019604475&gt;, type=&lt;C0&gt;, result=&lt;OK&gt;, ccType=&lt;&gt;), 
  170209 035711 0797 DE(N) ItemHandler.ItemLog event=&lt;REDIRECT_ITEM_REPLY&gt;, *******************, itemId=&lt;12560311&gt;, globalId=&lt;12560311&gt;, cmcIndex=&lt;755&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForDestination&gt;, CscdestinationId=&lt;3000: Parked0&gt;, chuteGroup=&lt;[3000]: Parked0&gt;, CmcdestinationId=&lt;3000: Parked0&gt;,
  170209 035711 0798 DE(N) ItemHandler.ItemLog event=&lt;ITEM_INDUCTED&gt;, *************************, itemId=&lt;12560311&gt;, globalId=&lt;12560311&gt;, cmcIndex=&lt;755&gt;, sorter=&lt;0: MS01&gt;, state=&lt;CSC: WaitForData&gt;, inductionId=&lt;3: IU04&gt;, inductionMode=&lt;SCANNER&gt;, inductStatus=&lt;NORMAL_ITEM&gt;, carrierId=&lt;469&gt;, carrierCount=&lt;1&gt;, CmcdestinationId=&lt;3000: Parked0&gt;, position=&lt;sorter#0: MS01&gt;, itemRevisionNumber=&lt;7&gt; ##[
  </code></pre>
  
  <p>Objective :</p>
  
  <p>What I want to do is using gawk in Windows is find the first occurance of ITEMID and grab the date and time and the last time occurance it was seen and grab the data and time. and put these onto one line such as </p>
  
  <pre><code>ITEMID  170209 035711   170209 035932
  </code></pre>
  
  <p>Is there a way I can do this using GREP or AWK or a combination</p>
  
  <p>Thanks</p>