python pipe stdout 实现cat|grep 功能
从hdfs里获取希望的数据:
import subprocess for day in range(22, 23):
for h in range(17, 24):
filename = "metadata-2018-10-%02d-%02d.txt" % (day, h)
cmd = "hdfs dfs -text /flume/metadata/2018/10/%02d/%02d/*.snappy" % (day, h)
print(cmd)
#cmd = "cat *.py"
cmd = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
f = open(filename, "w")
for line in cmd.stdout:
try:
arr = line.split("^")
if len(line) > 100 and arr[6] == "6":
#print(line)
f.write(" ".join(arr[:32]) + " " + arr[95] + "\n")
except Exception as e:
print(e, "fuck error", line)
f.close()
#import sys
#sys.exit(0)
python pipe stdout 实现cat|grep 功能的更多相关文章
- Python练习-迭代器-模拟cat|grep文件
代码如下: # 编辑者:闫龙 def grep(FindWhat): f=open("a.txt","r",encoding="utf8") ...
- Python中模块之os的功能介绍
Python中模块之os的功能介绍 1. os的变量 path 模块路径 方法:os.path 返回值:module 例如:print(os.path) >>> <module ...
- python操作三大主流数据库(6)python操作mysql⑥新闻管理后台功能的完善(增、ajax异步删除新闻、改、查)
python操作mysql⑥新闻管理后台功能的完善(增.删.改.查)安装表单验证D:\python\python_mysql_redis_mongodb\version02>pip instal ...
- 线上问题debug过程(cat,grep,tr,awk,sort,uniq,comm等工具的综合使用)
问题:发现线上到货单的数量,小于实际到货的数量. 怀疑一些隐藏的条件,将部分唯一码进行了过滤,导致数量变少. 开展了如下的跟踪流程: 1.找到其中一个明细的唯一码 grep 6180e-4b09f p ...
- Python实现Linux命令xxd -i功能
目录 Python实现Linux命令xxd -i功能 声明 一. Linux xxd -i功能 二. xxd -i常见用途 三. 类xxd -i功能的Python实现 Python实现Linux命令x ...
- Python实例--12306的抢票功能
基础知识学习 目标: 通过python程序实现自动登录下单功能 知识点: Selenium + 云打码 + Python 学习链接: 1. Python学习--Selenium模块 2. Python ...
- python模块之importlib(py3中功能有明显加强)
# -*- coding: utf-8 -*-#python 27#xiaodeng#python模块之importlib(py3中功能有明显加强)
- Python实现字符串与数组相互转换功能示例
Python实现字符串与数组相互转换功能示例 本文实例讲述了Python实现字符串与数组相互转换功能.分享给大家供大家参考,具体如下: 字符串转数组 str = '1,2,3' arr = s ...
- Python 3.10 中新的功能和变化
随着最后一个alpha版发布,Python 3.10 的功能更改全面敲定! 现在,正是体验Python 3.10 新功能的理想时间!正如标题所言,本文将给大家分享Python 3.10中所有重要的功能 ...
随机推荐
- 小测(noip2005的两道题) 2017.3.3
过河 题目描述 Description 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把 ...
- git源码阅读
https://github.com/git-for-windows/git/issues/1854 https://github.com/git-for-windows/git/pull/1902/ ...
- Spring batch的学习
Spring batch是用来处理大量数据操作的一个框架,主要用来读取大量数据,然后进行一定处理后输出成指定的形式. Spring batch主要有以下部分组成: JobRepository ...
- layer.alert自定义关闭回调事件
在项目应用中,遇到自定义关闭layer.alert弹出层,即在关闭layer.alert时,可以自动触发关闭时的事件, 具体方法为: layer.alert('爱心提示!', function(){ ...
- NYOJ 16 矩形嵌套(经典DP)
http://acm.nyist.net/JudgeOnline/problem.php?pid=16 矩形嵌套 时间限制:3000 ms | 内存限制:65535 KB 难度: ...
- codevs 1200 同余方程 逆元
题目描述 Description 求关于 x 同余方程 ax ≡ 1 (mod b)的最小正整数解. 输入描述 Input Description 输入只有一行,包含两个正整数 a, b,用 一个 空 ...
- js 二进制转换为16进制数
<!DOCTYPE html> <html> <head> <title>远程监控</title> </head> <bo ...
- 模型层model layer
题外话: Django的教程写到这里,就进入了整体的第二部分,也是最关键的部分.此时有一个问题必须想清楚,那就是,以项目带动内容还是以参考书目的方式展开?为此,我考虑了很久. 我在开始学习Django ...
- js 文件上传
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...
- jQuery.extend()意义及用途
一.意义 用于将一个或多个对象的内容合并到目标对象 二.用法: $.extend( [deep ], target, object1 [, objectN ] ) 注意: 1. 如果只为$.exten ...