在/home/test/2017-08-23這個目錄中查找包含0001a794d86f0844的文件
1、shell for循環
適用於hdfs容量比較小的的
for file in `hadoop fs -ls /home/test/2017-08-23 |awk '{print $NF}'`
do echo $file
hadoop fs -text $file |fgrep "0001a794d86f0844" --color
done
2、藉助hive中的虛擬列
適用於查找比較大的文件,藉助於mr
創建臨時表,只有一列。如:
create external table temp_find_table (line string )
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\\U0000'
location '/home/test/2017-08-23' ;
select line,INPUT__FILE__NAME ,BLOCK__OFFSET__INSIDE__FILE
from temp_find_table
where line like '%0001a794d86f0844%' ;
其中第2列是記錄所在文件位置,第3列是記錄在文件中的偏移量。