- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- using awk instead of wc -l
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
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
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
03-27-2012 06:55 AM
03-27-2012 06:55 AM
Hi,
I am wanting to use awk to count a nuimber of lines where the /match statment is true:
# cat file | awk -F':' '/^FDC-6/ && !/VMM/ {if($6 !~ /\-id/) print}' |wc -l
56
I want to know how I can count the lines using somethuing like i++ but struggling to get the syntax to work
# cat file | awk -F':' '/^FDC-6/ && !/VMM/; BEGIN{i=0};{if($6 !~ /-id/ then i++)};END{print i}'
but I know this is incorrect
any help much appreciated
Chris.
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2012 07:24 AM
03-27-2012 07:24 AM
Solution>I want to know how I can count the lines using something like i++ but struggling to get the syntax to work
Use separate lines to see it better:
awk -F':' '
BEGIN {i=0}
/^FDC-6/ && !/VMM/ {
if($6 !~ /-id/) i++
}
END{print i}' file
Which can be improved by combining your conditions:
/^FDC-6/ && !/VMM/ && ($6 !~ /-id/) { i++ }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2012 09:14 AM
03-28-2012 09:14 AM
Re: using awk instead of wc -l
cat filename | grep -i "yourtexttomatch" |grep -i "second_contidion" wc -l
Second thing using awk example :
#### Awk without condition for one match .
$ cat /tmp/sktest1|awk 'BEGIN {c=0} /Creating/ {c++ ;print c,$2,$3}'
1 Creating System
2 Creating Map
3 Creating Map
####### Awk with one condition and one match .
$ cat /tmp/sktest1|awk 'BEGIN {c=0} /Creating/ {if($3=="Map")c++ ;print c,$2,$3}'
0 Creating System
1 Creating Map
2 Creating Map
### Awk with two matches AND operation .
$ cat /tmp/sktest1|awk 'BEGIN {c=0} /Creating/ && /Map/ {c++ ;print c,$2,$3}'
1 Creating Map
2 Creating Map
Like this you can use any combination .
Hope this helps .
Sachin Rajput
=================
Sachin Rajput
================