imn1
V2EX  ›  问与答

这个 shell 命令怎么写

  •  
  •   imn1 · Nov 18, 2015 · 1627 views
    This topic created in 3856 days ago, the information mentioned may be changed or developed.
    从一个 url ( http://example.com/xxx.js) 获取一个文本,正则提取其中一个字串(唯一的),例如 newPath="ABC"; 提取 ABC
    然后和另一个字串组成新的 url 如: http://example.com/ABC/xxx.zip
    用 wget 下载这个 zip
    不需考虑 cookies ,所以懒得写爬虫,想用 shell 处理完就算了
    谢谢!!
    5 replies    2015-11-18 21:47:19 +08:00
    fising
        1
    fising  
       Nov 18, 2015
    这很难吗?
    yougg
        2
    yougg  
       Nov 18, 2015   ❤️ 1
    curl http://example.com/xxx.js 2>&1 | awk -F '[ ]*=[ ]*' '/newPath/{print "http://example.com/"$2"/xxx.zip"}' | xargs wget
    imn1
        3
    imn1  
    OP
       Nov 18, 2015
    @fising
    不熟就难,多是用到才查,主要 1.不清楚 m>&n 意思, 2.POSIX 不熟悉,所以不常用 awk

    @yougg
    谢谢,改了下,要把=改成",不然把 ABC 后面的";也捕获了
    fising
        4
    fising  
       Nov 18, 2015   ❤️ 1
    @imn1 Linux 文件描述符
    SoloCompany
        5
    SoloCompany  
       Nov 18, 2015   ❤️ 1
    2>&1 改成 2>/dev/null 你就容易看懂了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3586 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 04:53 · PVG 12:53 · LAX 21:53 · JFK 00:53
    ♥ Do have faith in what you're doing.