Find XML files non containing a specific comment from shell

前端 未结 2 920
梦如初夏
梦如初夏 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} // && !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 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.

提交回复
热议问题