Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. awk
  2.  
  3. BEGIN { FS = ","; col = "COLOR1"; i = 1 }
  4. !/^[0-9]/ { next }
  5.  
  6. $3 == "" {
  7. val = sprintf("%.0f", $2)
  8. data = data ? data OFS val : val
  9. col = col OFS "COLOR" ++i
  10. next
  11. }
  12.  
  13. $2 < min { min = $2 }
  14. $3 > max { max = $3 }
  15.  
  16. END {
  17. printf("NAME:nFROM= %s %snTO= %s %snCOLOR= %sn",
  18. min, data, data, max, col)
  19. }
  20.  
  21. $ awk -f script.awk file.csv
  22. NAME:
  23. FROM= -100 -346 -249 -125
  24. TO= -346 -249 -125 100
  25. COLOR= COLOR1 COLOR2 COLOR3 COLOR4
  26.  
  27. awk 'NR>1 && NR<5{
  28. v=sprintf("%.0f", $2); values=(values)? values FS v : v;
  29. lbl="COLOR"; col_item=lbl""++c; col=(col)? col OFS col_item : col_item
  30. }
  31. NR==6{ from=$2 }
  32. END{
  33. print "NAME :"; print "FROM=",from,values;
  34. print "TO=",values,$3; print "COLOR=",col,lbl""++c
  35. }' file
  36.  
  37. NAME :
  38. FROM= -100 -346 -249 -125
  39. TO= -346 -249 -125 100
  40. COLOR= COLOR1 COLOR2 COLOR3 COLOR4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement