Find XML files non containing a specific comment from shell

前端 未结 2 919
梦如初夏
梦如初夏 2021-01-29 03:27

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

相关标签:
2条回答
  • 2021-01-29 03:54

    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.

    0 讨论(0)
  • 2021-01-29 04:00

    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).

    0 讨论(0)
提交回复
热议问题