简体   繁体   中英

Searching Pattern after a specific pattern in bash script

i have to search 100 files of following format.

<dependencies>
<a1 build="true">
<a2 build="false">
<a3 build="false">
<deployments>
<a1 build="false">
<a2 build="true">
<a3 build="false">

I have to find all files who have atleast 1 deployment where build="true". The problem is how should i start the search after the string deployment so that dependencies where build="true" doesnot come into search.

awk 'FNR == 0 { dep = 0; }
     /<deployments>/ { dep = 1; }
     /build="true"/ && dep { print FILENAME; nextfile; }' file1 file2 ...

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