#!/usr/bin/gawk -f #/* vim: set filteype=awk : */ -*- awk -*- BEGIN{ IGNORECASE=1; alltreats=ENVIRON["treatments"] sub(/\,[ \t]*$/, "", alltreats) newtreats="" split(alltreats, treats, ",") for (J in treats) { sub(/^ /, "", newtreats) sub(/ $/, "", newtreats) gsub(/ /," ", newtreats) count++ } for (I in treats) { count2++ Unique[treats[I]]=Unique[treats[I]]+1; if(Unique[treats[I]]==1) { if(newtreats==""){newtreats=treats[I]} else{newtreats=newtreats "," treats[I]} } if(count2==count) { # sub(/^ /, "", newtreats) # sub(/ $/, "", newtreats) print newtreats exit } } }