我有这个代码:
curl -o fileName.csv url | xargs hdfs dfs -moveFromLocal $1 /somePath/
当我执行此代码时,curl 将请求中的值放入 fileName.csv 中,该文件将移动到 HDFS。我想知道我是否可以将curl 输出保留在内存中,发送到管道并将值写入HDFS 中?
像这样的东西(有效):
curl url | xargs hdfs dfs -put $1 /somePath
The hdfs dfs -put
命令可以接受来自标准输入的文件输入,使用熟悉的习惯用法指定-
表示标准输入:
> curl -sS https://www.google.com/robots.txt | hdfs dfs -put - /robots.txt
> hdfs dfs -ls /robots.txt
-rw-r--r-- 3 cnauroth supergroup 6880 2017-07-06 09:07 /robots.txt
另一种选择是使用 shell过程替代 http://tldp.org/LDP/abs/html/process-sub.html允许处理标准输出curl
(或者实际上是您选择的任何命令)就像它是另一个命令的文件输入一样:
> hdfs dfs -put <(curl -sS https://www.google.com/robots.txt) /robots.txt
> hdfs dfs -ls /robots.txt
-rw-r--r-- 3 cnauroth supergroup 6880 2017-07-05 15:07 /robots.txt
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)