V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
imn1
V2EX  ›  问与答

这个 shell 命令怎么写

  •  
  •   imn1 · 2015-11-18 15:08:25 +08:00 · 1245 次点击
    这是一个创建于 3120 天前的主题,其中的信息可能已经有所发展或是发生改变。
    从一个 url ( http://example.com/xxx.js) 获取一个文本,正则提取其中一个字串(唯一的),例如 newPath="ABC"; 提取 ABC
    然后和另一个字串组成新的 url 如: http://example.com/ABC/xxx.zip
    用 wget 下载这个 zip
    不需考虑 cookies ,所以懒得写爬虫,想用 shell 处理完就算了
    谢谢!!
    5 条回复    2015-11-18 21:47:19 +08:00
    fising
        1
    fising  
       2015-11-18 15:17:13 +08:00
    这很难吗?
    yougg
        2
    yougg  
       2015-11-18 15:26:22 +08:00   ❤️ 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
       2015-11-18 16:18:20 +08:00
    @fising
    不熟就难,多是用到才查,主要 1.不清楚 m>&n 意思, 2.POSIX 不熟悉,所以不常用 awk

    @yougg
    谢谢,改了下,要把=改成",不然把 ABC 后面的";也捕获了
    fising
        4
    fising  
       2015-11-18 16:26:24 +08:00   ❤️ 1
    @imn1 Linux 文件描述符
    SoloCompany
        5
    SoloCompany  
       2015-11-18 21:47:19 +08:00   ❤️ 1
    2>&1 改成 2>/dev/null 你就容易看懂了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3015 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 13:04 · PVG 21:04 · LAX 06:04 · JFK 09:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.