我有一个 bash 命令,列出 HDFS 中以/random
.
其过程如下:
hdfs dfs -ls -R /random | grep '^d' | awk '{print $NF}'
它生成以下输出:
/random/custom
/random/custom/hive
/random/custom/hive/jars
/random/app
/random/app/nifi
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie
/random/app/oozie/efdm
/random/app/oozie/efdm/ensco
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis
/random/app/oozie/gis/opk
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
我想修改我的命令,以便仅列出完整目录路径,如下所示:
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
你会怎么做?
答案1
您只想打印非目录文件吗?尝试通过管道传递结果
awk -F/ 'NF <= OLDNF {print LAST}; {OLDNF = NF; LAST = $0} END {print LAST}'
/random/custom/hive/jars
/random/app/nifi/egispub
/random/app/nifi/empgis
/random/app/nifi/ods
/random/app/nifi/ptcsm
/random/app/nifi/tmds
/random/app/nifi/ucmdb
/random/app/oozie/efdm/ensco/standardized_efdm_ensco_parser_5min/lib
/random/app/oozie/efdm/mermec/cleansed_efdm_mermec_5min
/random/app/oozie/efdm/mermec/standardized_efdm_mermec_5min
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/lib
/random/app/oozie/gis/opk/standardized_gis_opk_parser_10min/schemas
它查找读取路径的“增长深度”,并打印该路径是否缩小(返回目录深度)或保持相等(同一层次结构级别上的文件)。