Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- System Administration
- >
- awk to perl (sum on columns)
System Administration
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
-
- Forums
-
Blogs
- Alliances
- Around the Storage Block
- Behind the scenes @ Labs
- HPE Careers
- HPE Storage Tech Insiders
- Infrastructure Insights
- Inspiring Progress
- Internet of Things (IoT)
- My Learning Certification
- OEM Solutions
- Servers: The Right Compute
- Shifting to Software-Defined
- Telecom IQ
- Transforming IT
- Infrastructure Solutions German
- L’Avenir de l’IT
- IT e Trasformazione Digitale
- Enterprise Topics
- ИТ для нового стиля бизнеса
- Blogs
-
Quick Links
- Community
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Contact
- Email us
- Tell us what you think
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Enterprise.nxt
- Marketplace
- Aruba Airheads Community
-
Forums
-
Blogs
-
InformationEnglish
Go to solution
Topic Options
- 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-22-2009 07:47 AM
01-22-2009 07:47 AM
Hi
I wrote this small awk script. Objective is to sum columns...
echo $(cat $OUTPUT_FILE | awk 'NR > 0 {
countN1 += $2
countN2 += $3
}
END {
print "### countN1 countN2 "
}') >> $OUTPUT_FILE
How to do the same things but with perl ?
Bests Regards
Den
I wrote this small awk script. Objective is to sum columns...
echo $(cat $OUTPUT_FILE | awk 'NR > 0 {
countN1 += $2
countN2 += $3
}
END {
print "### countN1 countN2 "
}') >> $OUTPUT_FILE
How to do the same things but with perl ?
Bests Regards
Den
Solved! Go to Solution.
2 REPLIES
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-22-2009 08:27 AM
01-22-2009 08:27 AM
Solution
Hi Den:
One way:
perl -nale 'next if $.<2;$count1+=$F[1];$count2+=$F[2];END{print "### $count1 $count2"}' file
Remember, 'awk' numbers fields starting with one (1). Perl is more mathematical and starts at zero (0). The '-a' means "auto-split" into an array '@F'. The '-n' gives us a read loop for the file(2) specified as an argument. The '-l' adds a linefeed to each output line and the '-e' signals the script follows.
Regards!
...JRF...
One way:
perl -nale 'next if $.<2;$count1+=$F[1];$count2+=$F[2];END{print "### $count1 $count2"}' file
Remember, 'awk' numbers fields starting with one (1). Perl is more mathematical and starts at zero (0). The '-a' means "auto-split" into an array '@F'. The '-n' gives us a read loop for the file(2) specified as an argument. The '-l' adds a linefeed to each output line and the '-e' signals the script follows.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-22-2009 08:34 AM
01-22-2009 08:34 AM
Re: awk to perl (sum on columns)
Thanks again James! Perfect !
Bests Regards
Den
Bests Regards
Den
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2019 Hewlett Packard Enterprise Development LP