linux - Grep specific part of text -


i have text this:

ora.sas.aa.svc       1        online  online       sas1                                          ora.sas.bb.svc       1        online  online       sas2                                          ora.sas.cc.svc       1        online  online       sas2                                          ora.sas.dd.svc       1        online  online       sas1                                          ora.sas.ee.svc       1        online  online       sas1                                                2        online  online       sas2   

what want grep specific part of .svc , online status like:

example.txt |grep aa 
  ora.sas.aa.svc           1        online  online       sas1      

or

example.txt |grep ee 
 ora.sas.ee.svc       1        online  online       sas1                                                2        online  online       sas2   

row number of "online" may change, can't grep grep -a2 or grep -a3.

you can use awk instead:

awk -v s='ee' 'nf==1 && $0 ~ s{p=1} nf==1 && !($0 ~ s){p=0} p' file ora.sas.ee.svc       1        online  online       sas1       2        online  online       sas2  awk -v s='aa' 'nf==1 && $0 ~ s{p=1} nf==1 && !($0 ~ s){p=0} p' file ora.sas.aa.svc       1        online  online       sas1 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -