【问题标题】:Curl with cat in xargs is not working在 xargs 中使用 cat 卷曲不起作用
【发布时间】:2018-11-06 13:43:14
【问题描述】:

如何修改:

seq 1 10 | xargs -I{} -P2 -- curl -O -s 'https://example.com/dir/{}.ts

为了这个?

cat links.txt | xargs -I{} -P10 -- curl -O -s 'https://example.com/dir/{}.ts'

我不需要从 1-10 的序列,我需要将 seq 1 10 替换为 cat links.txt,因为 links.txt 不包含它包含的数字

aada1
adk29
amn22

【问题讨论】:

    标签: curl parallel-processing xargs


    【解决方案1】:

    如果 links.txt 中的项目各占一行,那么解决方案就像你写的那样

    cat links.txt | xargs -I{} -P10 -- curl -O -s 'https://example.com/dir/{}.ts'
    

    如果项目位于由空格分隔的单行上,则将空格转换为新行

    cat links.txt | tr ' ' '\n' | xargs -I{} -P10 -- curl -O -s 'https://example.com/dir/{}.ts'
    

    单独使用 xargs 直接从文件中读取并设置分隔符

    # populate test.txt with space separated items
    echo -n 'ooo234 qqq345 mmm654' > test.txt
    xargs --delimiter=' ' --arg-file=test.txt -I '{}' echo "'{}'" 
    

    一次使用一个以空格分隔的项目

    'ooo234'
    'qqq345'
    'mmm654'
    

    如果项目是换行符:

    xargs --delimiter='\n' --arg-file=test.txt -I '{}' echo "'{}'"
    

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 2018-06-05
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2013-02-05
      相关资源
      最近更新 更多