我有一个包含102个子目录和1590个文件的目录。我尝试递归地对所有文件运行以下命令,包括名称中带有空格的文件,以便将包含400个标签的列表从#tag更改为[[link]].
find . -name '*.md' | xargs sed -i -f sedfile *.md它只适用于文件名中没有空格的文件。sedfile的格式为s/#tag/[[link]]/g
sed: can't read ./4.Programming/G-Code/List: No such file or directory
sed: can't read of: No such file or directory
sed: can't read Common: No such file or directory
sed: can't read G-Code: No such file or directory
sed: can't read Commands: No such file or directory
sed: can't read and: No such file or directory
sed: can't read What: No such file or directory
sed: can't read They: No such file or directory
sed: can't read Mean.md: No such file or directory文件名是4.编程/G代码/通用G代码命令列表和它们的Mean.md。
我之前用过
find . -type f -name "*.md" -print0 | xargs -0 sed -i '' -e 's/#tag/[[link]]/g'进行单独的更改,但我不期待手动更改390+更多。
当我尝试将这两者结合起来时
find . -name '*.md' print0 | xargs -0 sed -i -f sedfile *.md我得到了
find: paths must precede expression: `print0`到目前为止,我在我的研究中找到的文章展示了如何对单个文件进行多次更改或对多个文件进行一次更改。如何编辑这两个示例中的任何一个以覆盖目录中的*.md文件?
发布于 2021-11-04 13:05:57
这里有一个拼写错误:您使用print0而不是-print0。
您也不需要*.md,因为xargs提供了文件名。
这应该是可行的:
find . -name '*.md' -print0 | xargs -0 sed -i -f sedfile您也可以改用-exec:
find . -name '*.md' -exec sed -i -f sedfile {} +https://stackoverflow.com/questions/69839376
复制相似问题