Advertisement
a_9

unnecessary awk

a_9
Jan 23rd, 2016
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.88 KB | None | 0 0
  1. BEGIN{
  2.     FS = ","
  3.     hex_regexp = "^#[0-9a-fA-F]{8}$"
  4. }
  5.  
  6. /#/{
  7.     for (f=1; f<=NF; f++)
  8.     {
  9.         if ( $f ~ hex_regexp )
  10.         {
  11.             len = length(all_vals) + 1
  12.             all_vals[len] = substr($f, 0, 7)
  13.         }
  14.     }
  15. }
  16.  
  17. END{
  18.     PROCINFO["sorted_in"] = "@val_str_asc"
  19.  
  20.     for (i in all_vals)
  21.     {
  22.         a = all_vals[i]
  23.         matched = 0
  24.         for (j in unique_vals)
  25.         {
  26.             b = unique_vals[j]
  27.             if (a == b)
  28.             {
  29.                 matched = 1
  30.                 break
  31.             }
  32.         }
  33.         if (matched == 0)
  34.         {
  35.             len = length(unique_vals) + 1
  36.             unique_vals[len] = a
  37.         }
  38.     }
  39.  
  40.     for (i in unique_vals)
  41.     {
  42.         if ( i != length(unique_vals) )
  43.             print "\"" unique_vals[i] "\","
  44.         else
  45.             print "\"" unique_vals[i] "\""
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement