Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple match 1

Status
Not open for further replies.

Calz

Technical User
Nov 14, 2001
103
0
0
FR
Can anyone help, bit of a noob to awk so strugling here

This is a netbackup command that produces an output with many fields, we ignore the first 3 lines, I'm trying to ignore field $12 of "ABC" "DEF" "GHI" and produce a count but in the case of DEF I also need to ignore anything that starts with A on $1 so need $1 !~/A/ but not sure how to combine them together, if I just add $1 !~/A/ in it excludes everything that starts with A

vmquery -w -a |awk 'NR>3 && $12!="ABC" && $12!="DEF" && $12!="GHI" {n++}; END {print n+0}'
 
Hi

Calz said:
if I just add $1 !~/A/ in it excludes everything that starts with A
No. That would ignore those containing A in the 1[sup]st[/sup] field.

Field 1 not starts with A has to be written as [tt]$1!~/[red]^[/red]A/[/tt] .


Feherke.
 
Thanks, it achieves the same result in my file but doesn't solve the initial problem.
 
Perhaps:

Code:
vmquery -w -a |awk 'NR>3 && $12!="ABC" && !($12=="DEF" && $1 =~ /^A) && $12!="GHI" {n++}; END {print n+0}'

Or personally I find it easier not having lots of nots (it ties me in knots) :) :

Code:
vmquery -w -a |awk 'NR>3 && !($12=="ABC" || ($12=="DEF" && $1 =~ /^A) || $12=="GHI") {n++}; END {print n+0}'

Annihilannic.
 
Thanks but with both od those I get...

awk: syntax error near line 1
awk: bailing out near line 1
 
Sorry, some typos... change =~ to just ~ (I've been writing too much perl lately), and terminate my regexp's with another /.

Annihilannic.
 
I had to tweak it a bit for what I wanted ultimately but all working, thanks :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top