title: AWK multiple field separators | count different pattern found in field
body: <p>Good afternoon,</p>
  
  <p><strong>1.AWK multiple field separators</strong></p>
  
  <p>my first question is whether having 2 field separators once located field for separator 1, how do i get inside the field that is not number one for second separator? eg:</p>
  
  <p><strong>Command</strong></p>
  
  <pre><code>zcat  /home/technic/scripts/informe/datos/datos* \
  | egrep -m1 "\|435\|t|\|0\|t"| grep ";CI[0-9]" \
  | awk -F "[|;]" '{print $17}'
  
  **record $17 (FS="|")**
  
  2013-08-04;2013-08-10;CI6785,;HG=S;BD=S;AD=2,;NI=1,;SA,;TH,;HB=S;RG=S;PO=S;VI=S;
  </code></pre>
  
  <p>I want to get CI6785,</p>
  
  <p>There is a very specific reason why i need to do it this way since the awk command has various filters most of them cut by "|" and in only some cases get by ";" on same awk.</p>
  
  <p><strong>2.count different pattern found in field</strong></p>
  
  <p>This case wants to have a behaviour similar to the following:</p>
  
  <pre><code>{!a["ERR|"$3"|"$15]++ || !a["IPS|"$18]++ || !a["HTTPS|"$22]++};
  for(i in a) print a[i]"|"i;
  </code></pre>
  
  <p>--this returns the count of each different record found.</p>
  
  <p>if i do this:</p>
  
  <pre><code>zcat  /home/technic/scripts/informe/datos/datos* \
  | awk -F "|" --posix '!match($0, / ([0-9]{2}:){2}/);{print substr($0, RSTART, RLENGTH)}' \
  | sort | uniq -c
  </code></pre>
  
  <p>i get the following result(part of it):</p>
  
  <pre><code>418  23:50:
  392  23:51:
  393  23:52:
  373  23:53:
  336  23:54:
  321  23:55:
  348  23:56:
  366  23:57:
  326  23:58:
  341  23:59:
  </code></pre>
  
  <p>which basically gives me the count for every minute found, now i want to do this as first example and not have to run through a sort and uniq.</p>
  
  <p>I need this to work to be able to add another clause of comparisong.</p>
  
  <p>Please help most appreciated!</p>
  
  <p>forgot to put whole awk to see the picture:</p>
  
  <pre><code>for DATO in {1..3}  
  do       
   DATOS=$(zcat  /home/technic/scripts/informe/datos/datos"$DATO"_"$AGENCIA".tmp.gz | grep "AG|$AGENCIA" | awk -F "|" --posix 'BEGIN \
      { \
          CI=0 ; CI5 =0; CI7 =0; CI10 =0; CI20 =0; \
          H=0 ; H5 =0; H7 =0; H10 =0; H20 =0; \
          A=0 ; A5 =0; A7 =0; A10 =0; A20 =0; \
          G=0 ; G5 =0; G7 =0; G10 =0; G20 =0; \
      } \
  
      {!a["ERR|"$3"|"$15]++ || !a["IPS|"$18]++ || !a["HTTPS|"$22]++}; \
      /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;CI[0-9]{1,}/ {CI++} ; \
      CI &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;CI[0-9]{1,}/ &amp;&amp; $14 &lt; 5000 {CI5++} ; \
      CI &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;CI[0-9]{1,}/ &amp;&amp; $14 &gt;= 5000 &amp;&amp; $14 &lt; 7000 {CI7++} ; \
      CI &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;CI[0-9]{1,}/ &amp;&amp; $14 &gt;=7000 &amp;&amp; $14 &lt; 10000 {CI10++} ; \
      CI &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;CI[0-9]{1,}/ &amp;&amp; $14 &gt;=10000&amp;&amp; $14 &lt; 20000 {CI20++} ; \
  
      /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;H[0-9]{1,}/ {H++} \
      H &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;H[0-9]{1,}/ &amp;&amp; $14 &lt; 5000 {H5++} ; \
      H &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;H[0-9]{1,}/ &amp;&amp; $14 &gt;= 5000 &amp;&amp; $14 &lt; 7000 {H7++} ; \
      H &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;H[0-9]{1,}/ &amp;&amp; $14 &gt;=7000 &amp;&amp; $14 &lt; 10000 {H10++} ; \
      H &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;H[0-9]{1,}/ &amp;&amp; $14 &gt;=10000&amp;&amp; $14 &lt; 20000 {H20++} ; \
  
      /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;A[0-9]{1,}/ {A++} \
      A &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;A[0-9]{1,}/ &amp;&amp; $14 &lt; 5000 {A5++} ; \
      A &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;A[0-9]{1,}/ &amp;&amp; $14 &gt;= 5000 &amp;&amp; $14 &lt; 7000 {A7++} ; \
      A &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;A[0-9]{1,}/ &amp;&amp; $14 &gt;=7000 &amp;&amp; $14 &lt; 10000 {A10++} ; \
      A &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;A[0-9]{1,}/ &amp;&amp; $14 &gt;=10000&amp;&amp; $14 &lt; 20000 {A20++} ; \
  
      /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;G[0-9]{1,}/ {G++} \
      G &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;G[0-9]{1,}/ &amp;&amp; $14 &lt; 5000 {G5++} ; \
      G &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;G[0-9]{1,}/ &amp;&amp; $14 &gt;= 5000 &amp;&amp; $14 &lt; 7000 {G7++} ; \
      G &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;G[0-9]{1,}/ &amp;&amp; $14 &gt;=7000 &amp;&amp; $14 &lt; 10000 {G10++} ; \
      G &gt; 0 &amp;&amp; /\|GetAvail/ &amp;&amp; /\|435\|t|\|0\|t/ &amp;&amp; $17 ~ /;G[0-9]{1,}/ &amp;&amp; $14 &gt;=10000&amp;&amp; $14 &lt; 20000 {G20++} ; \
      END {
      if (CI &gt; 0){ print "DISPOCI|"CI"|"CI5"|"(CI5*100/CI)"|"CI7"|"(CI7*100/CI)"|"CI10"|"(CI10*100/CI)"|"CI20"|"(CI20*100/CI); } \
      if (H &gt; 0){ print "DISPOH|"H"|"H5"|"(H5*100/H)"|"H7"|"(H7*100/H)"|"H10"|"(H10*100/H)"|"H20"|"(H20*100/H); } \
      if (A &gt; 0){ print "DISPOA|"A"|"A5"|"(A5*100/A)"|"A7"|"(A7*100/A)"|"A10"|"(A10*100/A)"|"A20"|"(A20*100/A); } \
      if (G &gt; 0){ print "DISPOG|"G"|"G5"|"(G5*100/G)"|"G7"|"(G7*100/G)"|"G10"|"(G10*100/G)"|"G20"|"(G20*100/G); } \
      for(i in a) print a[i]"|"i; \
      }';)" "
      echo ${DATOS[@]} | sed "s/[ ][ ]*/\n/g" | grep 'DISPO'
      echo "todos los datos en array de dispos ++++++++++++++++++++++"
  for REC in $(echo ${DATOS[@]} | sed "s/[ ][ ]*/\n/g" | grep 'DISPO')
  do
      echo $REC | awk -F "|" '{print $1}'
      if [ -z ${DISPO[$(echo $REC | awk -F "|" '{print $1}')]} ];then
          echo "no ha encontrado añado registro ++++++++++++++++++++++++"
          DISPO[$(echo $REC | awk -F "|" '{print $1}')]=$(echo $REC | awk -F "|" '{print $2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$9"|"$10}')
          echo ${DISPO[$(echo $REC | awk -F "|" '{print $1}')]}"&lt;----------------- valor dentro de array"
      else
         echo "na encontrado sumo registro ++++++++++++++++++++++++"
         PARAM1=$(($(echo ${DISPO[$(echo $REC | awk -F "|" '{print $1}')]} | awk -F "|" '{print $1}') + $(echo $REC | awk -F "|" '{print $2}'))); echo "$PARAM1&lt;------------parametro 1"
         PARAM2=$(($(echo ${DISPO[$(echo $REC | awk -F "|" '{print $1}')]} | awk -F "|" '{print $2}') + $(echo $REC | awk -F "|" '{print $3}'))); echo "$PARAM2&lt;------------parametro 2"
         PARAM3=$(($(echo ${DISPO[$(echo $REC | awk -F "|" '{print $1}')]} | awk -F "|" '{print $4}') + $(echo $REC | awk -F "|" '{print 5}'))); echo "$PARAM3&lt;------------parametro 3"
         PARAM4=$(($(echo ${DISPO[$(echo $REC | awk -F "|" '{print $1}')]} | awk -F "|" '{print $6}') + $(echo $REC | awk -F "|" '{print $7}'))); echo "$PARAM4&lt;------------parametro 4"
         PARAM5=$(($(echo ${DISPO[$(echo $REC | awk -F "|" '{print $1}')]} | awk -F "|" '{print $8}') + $(echo $REC | awk -F "|" '{print $9}'))); echo "$PARAM5&lt;------------parametro 5"
         PORC1=$(echo "scale=2;($PARAM2*100)/$PARAM1" | bc);PORC2=$(echo "scale=2;($PARAM3*100)/$PARAM1" | bc);PORC3=$(echo "scale=2;($PARAM4*100)/$PARAM1" | bc);PORC4=$(echo "scale=2;($PARAM5*100)/$PARAM1" | bc)
         DISPO[$(echo $REC | awk -F "|" '{print $1}')]="$PARAM1|$PARAM2|$PORC1|$PARAM3|$PORC2|$PARAM4|$PORC3|$PARAM5|$PORC4"                          
      fi
  done
  for REC in $(echo ${DATOS[@]} | sed "s/[ ][ ]*/\n/g" | grep 'ERR|')
  do
      echo "$REC"
      echo "------- ERR -------"
  done
  for REC in $(echo ${DATOS[@]} | sed "s/[ ][ ]*/\n/g" | grep 'IPS|')
  do
      echo "$REC"
      echo "------- IPS -------"
  done    
  for REC in $(echo ${DATOS[@]} | sed "s/[ ][ ]*/\n/g" | grep 'HTTPS|')
  do
      echo "$REC"
      echo "------- HTTPS -------"
  done         
  done
  </code></pre>
  
  <p>o_0budaya0_o</p>