views:

99

answers:

2

i am trying to execute awk script below on solaris but it's giving error like

awk: syntax error near line 3
awk: bailing out near line 3

where is error can you help me to fix it ?

Input file:

$ cat details.txt
Manager1|sw1
Manager3|sw5
Manager1|sw4
Manager2|sw9
Manager2|sw12
Manager1|sw2
Manager1|sw0

Output required: Group the similar (based on $1) fields($2) together, i.e. group the engineers which are under a particular common manager. i.e. required output:

Manager1|sw1,sw4,sw2,sw0
Manager2|sw9,sw12
Manager3|sw5

Awk solution:

$ awk '
   BEGIN {FS=OFS="|"}
   !A[$1] {A[$1] = $0; next}
   {A[$1] = A[$1] "," $2}
   END {for(i in A) {print A[i]}
}' details.txt
+2  A: 

Solaris ... You probably need to run "nawk" instead of "awk".

janm
+1  A: 

in solaris, use nawk or /usr/xpg4/bin/awk

ghostdog74