【问题标题】:xargs repeated copy file based on text file inputxargs 根据文本文件输入重复复制文件
【发布时间】:2013-06-05 04:57:58
【问题描述】:

给定一个 PDF 文件(例如 file.pdf)和一个包含名称列表(例如 joe、fred、sam)的文本文件(例如 names.txt),我如何将 pdf 文件复制到新文件夹(例如 dir)多次,以便新文件包含文本文件中的名称。

file.pdf 复制到 dir/joe_file.pdf dir/fred_file.pdf dir/sam_file.pdf

我尝试使用 xarg 没有成功

cat names.txt | xargs cp file.pdf dir/{}_file.pdf

有什么想法吗?

使用 OSX 来做到这一点。

【问题讨论】:

    标签: macos bash xargs cp


    【解决方案1】:

    使用循环来实现:

    for line in $(cat names) ; do cp file.pdf dir/${line}_file.pdf; done
    

    【讨论】:

      【解决方案2】:

      最后,我使用了以下内容,这是一种享受。感谢您的帮助!

      cat names.txt | xargs -I{} cp file.pdf "{}"\ file.pdf
      

      【讨论】:

        【解决方案3】:
         for fl in `cat names.txt`
          do 
           cp file.pdf dir/${fl}_file.pdf
          done 
        

        希望这会有所帮助!

        【讨论】:

          【解决方案4】:

          使用 GNU 并行:

          parallel cp file.pdf dir/{}_file.pdf :::: names
          

          如果你需要为一堆pdf文件做:

          parallel cp {2} dir/{1}_{2} :::: names ::: *.pdf
          

          了解有关 GNU Parallel 的更多信息:https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

          10 秒安装:

          wget pi.dk/3 -qO - | sh -x
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-01-31
            • 2016-04-26
            • 1970-01-01
            • 2018-08-13
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多