方法1: shell for循环
for file in `hadoop fs -ls file_dir|awk '{print $NF}'`
echo $file
hadoop fs -text $file |grep -5 regular_exp --color >> savefile
done
方法2:直接用hadoop命令
hadoop fs -text file_dir/* | grep regular_exp >> savefile
file_dir 指hadoop中的文件目录
-5表示显示匹配行的前后5行
savefile表示保存查找结果的文件