![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help needed in sed | Alecs | Shell Programming and Scripting | 1 | 06-14-2008 02:46 PM |
| Help Needed in SED | raghav1982 | Shell Programming and Scripting | 4 | 04-07-2008 04:04 AM |
| SED Help Needed | Tide | UNIX for Dummies Questions & Answers | 2 | 01-28-2008 06:14 AM |
| Help Needed -sed | ravi.sadani19 | Shell Programming and Scripting | 9 | 10-06-2006 03:54 AM |
| Scp Help Needed !!!! | scooter17 | UNIX for Dummies Questions & Answers | 3 | 09-20-2006 01:50 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Awk help needed..
I have to add number in column 1 by month.
1531 Feb 1 2007 pgaps_p007_27909.trc 1529 Feb 1 2007 pgaps_p006_27907.trc 1533 Feb 1 2007 pgaps_p005_27905.trc 635 Apr 7 2007 pgaps_smon_2347.trc 634 Apr 7 2007 pgaps_lgwr_2343.trc 634 Apr 8 2007 pgaps_lgwr_2311.trc 613 Apr 10 2007 pgaps_p004_402.trc 615 Apr 10 2007 pgaps_p002_7500.trc 698 May 2 2007 pgaps_smon_2339.trc 634 May 5 2007 pgaps_lgwr_2335.trc 656 Mar 1 2007 pgaps_smon_8006.trc 634 Mar 3 2007 pgaps_lgwr_8002.trc 634 Mar 4 2007 pgaps_lgwr_2383.trc 641 Mar 8 2007 pgaps_qmn0_20351.trc Output should be : Feb 4593 Apr 3131 May 3897 When I run below awk command I am not getting desired output. ls -ltr |awk 'BEGIN { OFS = "\t"; ORS = "\n\n" } { print $1, $2, $3, $4 }'| awk '{tot=tot+$1}END{print tot}' Any help would be greatly appreciated. |
|
||||
|
I don't get that kind of output with ls -l but assuming you do, the following ought to work. Code:
ls -l | awk '{ tot[$2] += $1 } END { for (t in tot) printf "%s\t%i\n", t, tot[t] }'
Requesting ls to sort the output is unnecessary, if you require chronological output order, some additional tricks will be needed. The array loop in awk for (x in y) traverses the keys of y in unpredictable order. Also the sample output you posted doesn't seem to agree with the input. I get the following Code:
Feb 4593 May 1332 Apr 3131 Mar 2565 Did I misunderstand your requirement, or is the sample output wrong? Looks like you accidentally summed Mar and May into the same category. |
|
||||
|
Era,
Thanks for the update. Your observation is absolutely correct. I removed first few colums of ls -ltr output as they are not needed in my script. When I run command provided by you I do not get intended output. ls -l | awk '{ tot[$2] += $1 } END { for (t in tot) printf "%s\t%i\n", t, tot[t] }' 354272 %ii 1 %ii Thanks, Prakash |
![]() |
| Bookmarks |
| Tags |
| sum by column, sum by month |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|