【问题标题】:How to get the value using shell script in hadoop mapper如何在hadoop映射器中使用shell脚本获取值
【发布时间】:2013-12-13 13:34:59
【问题描述】:

我想处理 PCAP 文件,然后使用 WholeFileInputFormat。 地图的输入是<filename,content>。 如何使用shell脚本获取内容?

【问题讨论】:

  • 地图的输入是
  • 我不明白这个问题。请提供示例输入和您想要的输出。
  • mapper 的输入是一个类似“key \t this is the value, and I \n want to get the value.”之类的文件。我想得到的输出是那个文件的一部分,比如“这是值,我想得到这个值。”,如何使用shell脚本来做到这一点?
  • 我的问题看起来像这样,但是value是一个文件的内容,文件有很多行[Links]stackoverflow.com/questions/15365871/…
  • 那么,给定一个文件名,返回内容减去第一行的“单词\t”?

标签: bash hadoop


【解决方案1】:
# test file:
echo -e "foo bar\tthis is\nthe rest of the content" > file

contents=$( sed '1s/[^\t]*\t//' file )
label=$( sed '1{ s/\t.*//; q }' file )

您必须引用变量以保留空格。

echo "$label"
echo "$contents"

除非您明确知道为什么不应该引用变量,否则您应该始终引用变量

【讨论】:

  • 当我回显 $contents 时,我得到“这是其余的内容”。但我想将此内容保留在 2 行中,换句话说,我希望保留 '\n' .
  • 感谢您的耐心解答,非常感谢。
  • Contents为16进制文件内容,\x00如何保留?
猜你喜欢
  • 1970-01-01
  • 2011-09-13
  • 2021-07-30
  • 2019-09-06
  • 1970-01-01
  • 1970-01-01
  • 2013-10-18
  • 2013-10-01
相关资源
最近更新 更多