[ssankar@localhost AWK]$ cat empdata.txt
1|100|sankar|dell|chennai
2|101|rahul|tcs|chennai
3|102|pal|cts|bangalore
4|103|kali|cts|bangalore
5|104|john|cts|bangalore
6|105|pal2|cts|bangalore
[ssankar@localhost AWK]$ cat sum.awk
BEGIN{
FS="|"
SNO=1 ;
EMPID=2 ;
NAME=3 ;
COMPANY=4 ;
LOCATION=5 ;
}
{
list[$4] += 1;
sum += $1 ;
}
END{
printf ("%d\n", sum) ;
for (comp in list)
{
printf("%s %d \n", comp, list[comp]);
}
}
[ssankar@localhost AWK]$ awk -f sum.awk empdata.txt
21
tcs 1
dell 1
cts 4
[ssankar@localhost AWK]$
1|100|sankar|dell|chennai
2|101|rahul|tcs|chennai
3|102|pal|cts|bangalore
4|103|kali|cts|bangalore
5|104|john|cts|bangalore
6|105|pal2|cts|bangalore
[ssankar@localhost AWK]$ cat sum.awk
BEGIN{
FS="|"
SNO=1 ;
EMPID=2 ;
NAME=3 ;
COMPANY=4 ;
LOCATION=5 ;
}
{
list[$4] += 1;
sum += $1 ;
}
END{
printf ("%d\n", sum) ;
for (comp in list)
{
printf("%s %d \n", comp, list[comp]);
}
}
[ssankar@localhost AWK]$ awk -f sum.awk empdata.txt
21
tcs 1
dell 1
cts 4
[ssankar@localhost AWK]$
No comments:
Post a Comment