Bash loop over files in hdfs directory
I need to loop over all csv files in a Hadoop file system. I can list all of the files in a HDFS directory with
> hadoop fs -ls /path/to/directory
Found 2 items
drwxr-xr-x - hadoop hadoop 2 2016-10-12 16:20 /path/to/directory/tmp
-rwxr-xr-x 3 hadoop hadoop 4691945927 2016-10-12 19:37 /path/to/directory/myfile.csv
and can loop over all files in a standard directory with
for filename in /path/to/another/directory/*.csv; do echo $filename; done
but how can I combine the two? I've tried
for filename in `hadoop fs -ls /path/to/directory | grep csv`; do echo $filename; done
but that gives me some nonsense like
Found
2
items
drwxr-xr-x
hadoop
hadoop
2
2016-10-12
....
这应该工作
for filename in `hadoop fs -ls /path/to/directory | awk '{print $NF}' | grep .csv$ | tr 'n' ' '`
do echo $filename; done
链接地址: http://www.djcxy.com/p/93730.html
上一篇: 正确的方式从ArgumentParser获取允许的参数
下一篇: Bash循环播放hdfs目录中的文件