This won't work for dynamic data. We need to eliminate duplicate entries only if it exists. You are nowhere checking for unique or duplicate entries in your logic.
while read -r fline; do
fmy_array+=("$fline")
echo $fline | awk 'NF>=3 {A[$1]=(A[$1] ORS $2) D[$1]=$3 } END { for (t in A) { print "TKT:", t print "ACTOR:", A[t] print "DEPT:", D[t] print "" }}'
done <<< "$1"
error output:
awk: cmd. line:1: NF>=3 {A[$1]=(A[$1] ORS $2) D[$1]=$3 } END { for (t in A) { print "TKT:", t print "ACTOR:", A[t] print "DEPT:", D[t] print "" }}
awk: cmd. line:1: ^ syntax error
--- Post updated at 12:52 PM ---
This solution did not help. Although it took care of the duplicate entries there is no way to determine the three field of each array element into "TKT", "ACTOR" & "DEPT"
here is the output I got:
--- Post updated at 01:06 PM ---
There is no files involved here.
Also, I have updated the Original post with the output of $1.
--- Post updated at 01:43 PM ---
grep -o '\S*' <<<"$1" | sort -u
<- This works but there is no order so i dont know which element is what as requested in the desired output. Can you please help assign this to get displayed as below:
egrep -o '(\S+\s+){2}\S+' <<<"$1" |
awk '
{A[$1]; B[$3]; C[$2]}
END { print "TKT:" cat(A) "\n\nDEPT:" cat(B) "\n\nACTOR:" cat(C)}
function cat(T)
{ s=""; for (i in T)
s = s RS i
return s
}'