我正在根据正则表达式搜索文件,然后我试图在这些文件中搜索内容。所以,例如,我有类似的东西
#Find all C++ files that match a certain pattern and then search them
find . -name "*.cpp" | grep "<name regex>" | xargs grep "<content regex>"
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是某些路径中有空格,这让xargs. 我知道如果我只是使用find,我可以使用-print0参数(以及-0参数xargs)来防止 xargs 将空格视为分隔符。有类似的东西grep吗?
还是我完全以错误的方式处理这个问题?天真地,findtogrep对xargs grep我来说很有意义,但我对产生相同结果的其他方法持开放态度。