美文网首页
shell 读取文件行

shell 读取文件行

作者: dataMaster | 来源:发表于2017-01-10 18:53 被阅读0次

最近通过Spark Streaming消费Kafka数据,消费的数据落到hdfs,一分钟一个小文件,昨天架构那边的同事告诉我要清理历史文件,但是目录太多,手动删比较慢,于是想到可以把文件目录都拿到,写入文本 path_to_clean.txt,通过shell循环读路径,并执行删除。

hdfs://nameservice1/user/hadoop/dw_realtime/dw_real_for_path_list/mb_pageinfo_hash2/date=2016-01-09
hdfs://nameservice1/user/hadoop/dw_realtime/dw_real_for_path_list/mb_pageinfo_hash2/date=2016-07-05
hdfs://nameservice1/user/hadoop/dw_realtime/dw_real_for_path_list/mb_pageinfo_hash2/date=2016-09-05
hdfs://nameservice1/user/hadoop/dw_realtime/dw_real_for_path_list/mb_pageinfo_hash2/date=2016-10-20
hdfs://nameservice1/user/hadoop/dw_realtime/dw_real_for_path_list/mb_pageinfo_hash2/date=2016-11-06
hdfs://nameservice1/user/hadoop/dw_realtime/dw_real_for_path_list/mb_pageinfo_hash2/date=2016-11-07
...

已下是代码。

方式一(我才采用的是这种)

#!/bin/bash

for line in `cat path_to_clean.txt`
do
   echo $line
   hadoop fs -rm -r $line
done

方式二

#!/bin/bash
while read line
do
    echo $line
done < path_to_clean.txt

方式三

#!/bin/bash
cat path_to_clean.txt | while read line
do
    echo $line
done

相关文章

  • shell读取文件三种方法

    Shell按行读取文件的3种方法 Shell按行读取文件的方法有很多,常见的三种方法如下: 要读取的文件: 写法一...

  • shell 读取文件行

    最近通过Spark Streaming消费Kafka数据,消费的数据落到hdfs,一分钟一个小文件,昨天架构那边的...

  • linux笔记

    cat /dev/null > ./null.txt 清空文件内容 shell 按行读取文件 ,不过for 是...

  • shell按行读取文件

    在shell中按行读取文件常用的方法如下: file.txt文件中内容如下:

  • 在Ubuntu下编写shell脚本读取文件

    需求功能: 从文件中读取每一行显示 统计总行数 在shell运行过程中指定文件 一、shell初体验 在想要保存文...

  • Shell 读取文件时碰到的诡异问题

    现象: 当时shell读取文件的每一行,然后打印每一行文本,类似如下代码echo "===========$lin...

  • 终端用shell读写plist文件

    【原帖置顶】shell文件中读取plist文件并实现shell中的数值计算 Mac操作plist文件用PlistB...

  • shell 读取文件

    查找文件内容 并赋值变量

  • Python IO 流

    转载请注明出处 读文件 读取整个文件 分段读取 按行读取代码 按行读取 二进制读取 写文件 文本写出 追加文件 二...

  • Python3 读取文件内容

    简单粗暴读取文件里面每一行 快速的读取文件里面每一行 遍历文件夹里所有文件,读取里面每一行

网友评论

      本文标题:shell 读取文件行

      本文链接:https://www.haomeiwen.com/subject/hhclbttx.html