I want to search (awk/grep/sed) into few XML files (pom.xml file) skipping some folder. Moreover,the first condition is that they must contain the tag
Store that text in a file named foo and then run:
find ... -exec awk -v RS='^$' 'NR==FNR{str=$0;next} /<module>/ && !index($0,str){print FILENAME}' foo {} +
Use whatever find options work for you to get the list of XML files. Whether you use -exec or pipe to xargs is up to you, I'm really just addressing the awk part as that seems to be what you're having trouble with.
The above uses GNU awk for multi-char RS and does a strict search for the entire contents of foo
appearing exactly as written as a string in each of the XML files and prints the name of any file that does contain <module>
but does not contain that string.
If that doesn't do what you want then edit your question to show a more complete sample input/output example including the text you want to search for in context in the input file.
You can use xmllint
to search for a node using xpath
xmllint --xpath '//module' */pom.xml
Its return codes can tell you when it was found (0
) or not (!= 0
).