【发布时间】:2017-11-17 06:47:48
【问题描述】:
我需要在目录树中搜索 XML 文件并在另一个目录 (staging_ojs_pootle) 上为它们创建链接,用文件路径命名这些链接(每个点替换斜线)。
bash 命令不起作用,我卡在替换部件上。似乎 xargs 中名为“file”的变量在替换代码(${file/\//.})中是不可访问的@
find directory/ -name '*.xml' | xargs -I 'file' echo "ln" file staging_ojs_pootle/${file/\//.}
${} 结果中的替换给了我一个空字符串。
尝试使用 sed 但正则表达式正在替换全部或仅替换最后一个斜杠:/
find directory/ -name '*.xml' | xargs -I 'file' echo "ln" file staging_ojs_pootle/file |sed -e '/^ln/s/\(staging_ojs_pootle.*\)[\/]\(.*\)/\1.\2/g'
问候
【问题讨论】:
-
file不是 shell 变量的名称,它是一个占位符,它被 xargs 替换为它正在处理的 XML 文件的名称。所以你不能在上面使用像${file...}这样的shell变量替换命令。如果您向我们展示一些示例输入和预期输出,我们可以为您提供帮助。
标签: string bash sed replace xargs