- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- awk problem..any help..
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 12:53 AM
тАО08-01-2006 12:53 AM
100129 1 1000
100136 1 1000
100136 1 1000
100144 1 1000
100144 1 1000
100148 1 1000
100181 1 1000
is there a way to get file like this:
100107 1 1000
100129 1 1000
100136 2 2000
100144 2 2000
100148 1 1000
100181 1 1000
any hints?
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 01:00 AM
тАО08-01-2006 01:00 AM
Re: awk problem..any help..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 01:03 AM
тАО08-01-2006 01:03 AM
Re: awk problem..any help..
awk '{c[$1]++; t[$1]+=$3}END{for(f in c)printf("%s %d %d\n",f,c[f],t[f])}' input_filename
Did the trick for me, see the evidence:
awk '{c[$1]++; t[$1]+=$3}END{for(f in c)printf("%s %d %d\n",f,c[f],t[f])}'
100107 1 1000
100129 1 1000
100136 1 1000
100136 1 1000
100144 1 1000
100144 1 1000
100148 1 1000
100181 1 1000
100107 1 1000
100129 1 1000
100144 2 2000
100148 1 1000
100181 1 1000
100136 2 2000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 01:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 01:18 AM
тАО08-01-2006 01:18 AM
Re: awk problem..any help..
awk 'BEGIN {prev1="BEGIN";prev2=0;prev3=0}
{if ($1 == prev1) {prev2=prev2 + $2;
prev3=prev3 + $3;
continue}
if (prev1 != "BEGIN") {print prev1 " " prev2 " " prev3}
prev1=$1;prev2=$2;prev3=$3}
END {print prev1 " " prev2 " " prev3}' filename
I thought the associated arrays approach was nicer, but there can never be too many examples :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 01:21 AM
тАО08-01-2006 01:21 AM
Re: awk problem..any help..
I prefer Perl.
# perl -ne '$line{$_}++;END{for $key (sort keys %line) {@a=split/ /,$key;print join " ",$a[0],$line{$key},$a[2]}}' file
...yields (in sorted output order:
100107 1 1000
100129 1 1000
100136 2 1000
100144 2 1000
100148 1 1000
100181 1 1000
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 02:01 AM
тАО08-01-2006 02:01 AM
Re: awk problem..any help..
# awk '{f[$1]++;s[$1]+=$3} END{for(i in f) print i,f[i],s[i]}' infile > outfile
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 03:01 AM
тАО08-01-2006 03:01 AM
Re: awk problem..any help..
sort -n inputfile| uniq -c |awk '{print $1,$2,$4}'
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 05:42 PM
тАО08-01-2006 05:42 PM
Re: awk problem..any help..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-01-2006 06:38 PM
тАО08-01-2006 06:38 PM
Re: awk problem..any help..
awk '{c[$1]+=$2; t[$1]+=$3}END{for(f in c)printf("%s %d %d\n",f,c[f],t[f])}' file >file1
I am new in awk and working with arrays in awk...so this confuses me little...
THANKS a LOOTT