【问题标题】:Listing files in hdfs and appending the output to a text file在 hdfs 中列出文件并将输出附加到文本文件
【发布时间】:2018-03-01 01:00:16
【问题描述】:

我想根据条件列出 hadoop 中的文件并将输出附加到文本文件中。以下是我正在使用的命令

hadoop fs -ls /path/ | grep 'xxx' | awk '{print $8}' >> /hdfs_path/test.txt

当我执行上面的命令时,它说下面的错误

-bash: /hdfs_path/test.txt: 没有那个文件或目录

但该文件存在于目录中。

【问题讨论】:

    标签: linux hadoop hdfs


    【解决方案1】:

    问题是stdout重定向只知道你的本地文件系统,对Hadoop一无所知,不能本地写入。对于 hdfs 交互,您需要坚持使用 hadoop fs 或更新的 hdfs dfs 命令。

    尝试appendToFile 作为您的管道命令。

    用法:hdfs dfs -ls /your/hdfs/path | grep 'xxx' | hdfs dfs -appendToFile - hdfs://your.hdfs.system/your/hdfs/path/paths.txt

    我唯一的另一种选择是将输出保存到本地文件系统,并在完成后将其上传到 HDFS(如果您需要)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 2011-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多