【问题标题】:getmerge command in hadoop datacopyhadoop datacopy中的getmerge命令
【发布时间】:2015-02-25 09:22:02
【问题描述】:

我的目标是读取目录中所有以“trans”开头的文件并将它们转换为单个文件并将该单个文件加载到 HDFS 位置

我的源目录是/user/cloudera/inputfiles/

假设在上面的目录中,有很多文件,但我需要所有以“trans”开头的文件

我的目标目录是 /user/cloudera/transfiles/

所以我在下面尝试了这个命令

hadoop dfs - getmerge /user/cloudera/inputfiles/trans* /user/cloudera/transfiles/records.txt

但上面的命令不起作用。

如果我尝试以下命令,那么它可以工作

hadoop dfs - getmerge /user/cloudera/inputfiles   /user/cloudera/transfiles/records.txt

关于如何从 hdfs 位置合并一些文件并将合并的单个文件存储在另一个 hdfs 位置的任何建议

【问题讨论】:

  • getmerge 命令是否仅适用于目录中的所有文件?

标签: hadoop


【解决方案1】:

getmerge命令的用法如下:

Usage: hdfs dfs -getmerge <src> <localdst> [addnl]

Takes a source directory and a destination file as input and 
concatenates files in src into the destination local file. 
Optionally addnl can be set to enable adding a newline character at the
end of each file.

它期望目录作为第一个参数。

你可以试试这样的 cat 命令:

hadoop dfs -cat /user/cloudera/inputfiles/trans* > /<local_fs_dir>/records.txt
hadoop dfs -copyFromLocal /<local_fs_dir>/records.txt /user/cloudera/transfiles/records.txt

【讨论】:

  • 好的,这意味着 getmerge 仅适用于目录中的所有文件。对吗?
  • 是的,目的地将是您的本地文件系统。
  • hadoop dfs -cat /user/cloudera/inputfiles/trans* > //records.txt。我问 trans1.txt 的最后一行和 trans2.txt 的第一行将显示在一行上。那么我该如何解决这个问题。我不想在一行中包含两行的两个内容
  • 这是因为文件末尾没有换行符。只需在创建源文件时将其添加到源文件中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-17
相关资源
最近更新 更多