![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How To Calculate | krishna_sicsr | Shell Programming and Scripting | 3 | 03-21-2009 01:49 PM |
| calculate 13 months ago | andrea_mussap | Shell Programming and Scripting | 4 | 11-21-2007 08:14 PM |
| calculate 13 months ago | andrea_mussap | Shell Programming and Scripting | 3 | 11-16-2007 03:18 PM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 12:15 PM |
| How to calculate with awk | whatisthis | Shell Programming and Scripting | 4 | 11-09-2005 12:39 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
||||
|
How to calculate a sum of certain records?
Hi,
i have a file where the records are like this. vt100 2048 D402 MG0010 0 586 262144 D403 MG0011 1000 486 8192 D404 MG0012 270 386 8192 A423 CC0177 40 586 65536 A424 CC0182 670 486 16384 A423 CC0183 100 486 16384 A425 CC0184 80 65000 4096 B407 EE1027 80 I want firstly, to count how many times each combination of the first 2 letters from the 4th field exist and print it like this: 3 MG or MG 3 5 CC I tried this : Code:
awk -F"\t" '{print $4}' pcs.txt | uniq -c
Secondly, I want to sum the second field for each differrent entry of the 3rd field and print them. Like this A423 24576 A425 16384 I tried this : Code:
awk -F"\t" '{a[$3]=$3;
for (i = 1; i <= NR; i++){
for (i = 1; i <= NR; i++){
if(a[++i] = $3){
size+=$2}
}
print a[i]" "size
}' pcs.txt
Please help me |
|
||||
|
Quote:
Code:
sed 's/.*\([A-Z][A-Z]\)[0-9]*.*/\1/p' pcs.txt |sort| uniq -c |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|