This post is start for me ... I stumped at something that I not sure as to how start on ... I tried so of your script that i honestly lost mind looking and looking here ... please help
COL1 COl2 COL3
12222 AUH FLUEH
12222 SSC OPERA
12222 SSC OPERA
(SSC shows 2 occurences & AUH1 Occurences)
12223 SSC OPERA
12223 AUH FLUEH
12223 SSC OPERA
12223 SSC OPERA
(SSC shows 3 occurences & AUH1 Occurences)
RESULT -
12222 SSC-2 AUH-1 OPERA-2 FLUEH-1
12223 SSC-3 AUH-1 OPERA-3 FLUEH-1
How should I do this?
-- All i do, is
awk -F"\t" '{a[$2" " $4]++;a[$2" " $4]+=$NF} END {for (i in a){print i,a}}' WINTER_SHOPPE
but that is not giving answer as it accounts only 2 column result.
Can anyone of you help please ?
Can only these four words appear and do you want to list 0 or more occurrences of these words in COL2 and COL3 for every distinct value in COL1, or do you just want to list the number of occurrences for anything that appears in COL2 and COL3 in no particular order?
Hi,
welcome to the unix and linux forum:-)
awk 'BEGIN{ORS="";}{a[$1"^"$2] ;a[$1"^"$3] ;}END{asort(a);for(i in a){split(i,b,"^");if(b[1] ~ l){print b[2]"-"a;}else{print "\n"b[1];}l=b[1];}}' file
It works when it is sorted. Please make sure you have asort.
Cheers,
Ranga:-)
Sorry,,, I saw error
awk: calling undefined function asort
...
Scrutinizer,
si, only AUH, FLUEH, SSC, OPERA, and SSC FLORE appear in data set.
Thank you.
Sebastian.
SSC FLORE is two words, no?
Hi,
i think you dont have asort funtion,
Try this one,
awk 'BEGIN{ORS="";f[1]="AUH";f[2]="FLUEH";f[3]="SSC";f[4]="OPERA";f[5]="FLORE";}{a[$1"^"$2] ;a[$1"^"$3] ;c[$1]=1;}END{for(i in c){print i;for(j=1;j<=length(f);j ){fld=f[j];if(a[i"^"fld]){print fld"-"a[i"^"fld];}}print "\n";}}' file
Cheers,
Ranga:-)
hi rangarasan/Scrutinizer,
I have this problem. This reply is not working. here is complete ..
/Users/ssthomas/ $cat file
12222 AUH FLUEH
12222 SSC OPERA
12222 SSC OPERA
12223 SSC OPERA
12223 SSC OPERA
12223 AUH FLUEH
12223 SSC FLORE
12223 SSC FLORE
Output soaking -
12222 SSC-2 AUH-1 OPERA-2 FLUEH-1
12223 SSC-4 AUH-1 OPERA-2 FLORE-2 FLUEH-1
or atleast this...
12222 SSC-2 AUH-1
12223 SSC-4 AUH-1
--- here --
/Users/ssthomas/ $awk 'BEGIN{ORS="";f[1]="AUH";f[2]="FLUEH";f[3]="SSC";f[4]="OPERA";f[5]="FLORE";}{a[$1"^"$2] ;a[$1"^"$3] ;c[$1]=1;}END{for(i in c){print i;for(j=1;j<=length(f);j ){fld=f[j];if(a[i"^"fld]){print fld"-"a[i"^"fld];}}print "\n";}}' file
awk: can't open file file
source line number 1
/Users/ssthomas/ $
-- Please help here.
Thank you.
Sebastian
Hi, try this:
awk '{A[$1,$2]++;A[$1,$3]++}END{for(i in A){split(i,I,SUBSEP); S[I[1]]=S[I[1]] FS I[2] "-" A}for(i in S)print i,S}' infile
PS: Don't forget to use
```text
```
tags for code and data samples, thank you..
1 Like
Scrutinizer,
very very thanks to you and smartness.
this is why I read this forum daily.
Sebastian.