简体   繁体   中英

using awk on part of characters

I'm trying to do awk to look for part of characters .

cat myfile.txt

SIFT    POLD    POLH    LRT     MT      MA
T       B       B       N       P       N
null    null    null    null    null    null
null    null    null    null    null    null
T;.;.;.;.;.     B       B       N       P       N
D       P       B       D       D       M
T       B       B       N       P       N
T;T;T;. B       B       N       P;P;P   N
D;.     P       B       N       P;P     .
T;.     B       B       N       P;P     .

In this example I want to get lines with SIFT = T (including "T;T;T;.") ; POLD = B; POLH = B; LRT = N; MT = P, MA = N

I would normally used awk to do the job , eg

awk -F'\t' '$1=="T" && $2=="B" && $3=="B" && $4=="N" && $5=="P" && $6=="N" myfile.txt 

However, the command above will exclude "T;T;T;." in column 1. How can I include this too?

You can use awk like below

$ awk '$1 ~ /T/' file
SIFT    POLD    POLH    LRT     MT      MA
T       B       B       N       P       N
T;.;.;.;.;.     B       B       N       P       N
T       B       B       N       P       N
T;T;T;. B       B       N       P;P;P   N
T;.     B       B       N       P;P     .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM