python实现类似于awk的功能
发布时间
阅读量:
阅读量
在使用命令行工具时,awk具备一定的便捷性,然而若需处理更为复杂的任务,对于不熟悉awk的用户而言可能会带来一定困难。考虑到深入掌握awk的必要性较低,可以选择使用Python编写简易程序来完成相关操作;而对于更复杂的需求,则可通过Python脚本实现,从而确保整体程序逻辑的一致性与可维护性。
#!/usr/bin/python
#coding:utf-8
import os
import sys
from getopt import getopt
#处理协程
def deallines(dealer,instream,paras):
sep = paras.get("sep","\t")
for line in instream:
fields = line.strip("\r\n").split(sep)
for result in dealer(line,fields) or ():
if type(result) == str:
yield result
elif type(result)
全部评论 (0)
还没有任何评论哟~
