Hadoop streaming practice: Bash script

Source: Internet
Author: User
Tags hadoop fs

Streaming supports using scripts as map and reduceProgram. The following describes a program for calculating the total number of rows of all files in a distributed manner.

1. Put the data to be retrieved into HDFS
$ Hadoop FS-put localfile/user/hadoop/hadoopfile

2. Write the map and reduce scripts. Remember to add executable permissions to the scripts.
Mapper. Sh
#! /Bin/sh <br/> WC-l 

CER Cer. Sh
#! /Bin/sh <br/> sum = 0 <br/> while read I <br/> DO <br/> let sum + = $ I <br/> done <br /> echo $ sum 

3. run:
$ hadoop streaming-Input/user/hadoop/hadoopfile-output/user/hadoop/result-mapper. /mapper. sh-reducer. /CER Cer. sh-file mapper. sh-file CER Cer. sh-jobconf mapred. reduce. tasks = 1-jobconf mapre. job. name = "sum_test"
Note:
-Input/user/hadoop/hadoopfile: directory of files to be processed
-output/user/hadoop/result: processing result storage directory
-file: Distribution mapper. SH and reducer. sh to HDFS
-jobconf mapred. reduce. tasks = 1: Number of reduce tasks

3. view the result:
$ hadoop FS-CAT/user/hadoop/result/part-00000

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.