Remove lines with specific pattern
Are you just trying to print lines where there's 2 or more non-zero values in $4 or $5? That'd be:
$ awk 'gsub(/[1-9][0-9]*/,"&",$4)>1 || gsub(/[1-9][0-9]*/,"&",$5)>1' fileT 11727 E 0:6:0:323:0:0 0:6:0:309:0:0T 11728 F 0:0:0:328:0:0 0:1:0:314:0:0
awk solution:
awk 'function get_count(s, c, len) { len=split(s,a,":"); while(len--) if(a[len]){ c++ } return c } BEGIN { FS=OFS="\t" }get_count($4) > 1 || get_count($5) > 1' file
function get_count(s, c, len) { ... }
- function returning the count of non-zero values in the given stringsplit(s,a,":")
- splitting the strings
into arraya
by separator:
while(len--) if(a[len]){ c++ }
- accumulating non-zero count
The output:
T 11727 E 0:6:0:323:0:0 0:6:0:309:0:0T 11728 F 0:0:0:328:0:0 0:1:0:314:0:0