脚本处理大数据文件
来源:互联网 发布:沙发的网络意思是什么 编辑:程序博客网 时间:2024/05/19 10:34
在处理XX行的生产问题时,碰到过一次一个几十个G的文件,其中有几万条数据有一些问题,应急版本又来不及下发。最后采用了脚本处理的方法。用时大概几分钟吧。
下面详细介绍脚本的处理过程。
处理的核心是利用sed将问题文件中的错误数据替换为正确的数据
1.由于文件中内容过多,为了防止误操作,首先将文件按列切分为多个文件(问题文件内容每行定长)。
cutfile.sh
#! /bin/kshif [ $# != 1 ]then echo "FORMAT: cutfile.sh inputfile !" exit 1;fifilename=$1head -n 1 $filename > .filehead.txttail -n +2 $filename > .filebody.txtcut -c1-44 .filebody.txt > .fileblock_1cut -c45-52 .filebody.txt > fileblock_2_gmt_date.txt # gmt_datecut -c53-68 .filebody.txt > .fileblock_3cut -c69-76 .filebody.txt > fileblock_4_local_date.txt # local_datecut -c77-82 .filebody.txt > .fileblock_5cut -c83-90 .filebody.txt > fileblock_6_settlement_date.txt # settlement_datecut -c91-98 .filebody.txt > fileblock_7_capture_date.txt # capture_datecut -c99-294 .filebody.txt > .fileblock_8cut -c295-302 .filebody.txt > fileblock_9_orig_date.txt # orig_datecut -c303- .filebody.txt > .fileblock_10touch .CUT.OK
2.对切分开的错误文件做统计,查找出错次数
uniqfile.sh
#! /bin/kshif [ $# != 1 ]then echo "FORMAT: nuiqfile.sh inputfile !" exit 1;fifilename=$1cat $filename | sort | uniq -c
3.对出错切分文件进行替换操作
#! /bin/kshif [ $# != 3 ]then echo "FORMAT: sedfile.sh filename replacebefore replaceafter!" exit 1;fiif [ ! -f .CUT.OK ];then echo "please cut file,first!" exit 0fifilename=$1repstr1=$2repstr2=$3sed "s/${repstr1}/${repstr2}/" $filename > .sedtmpfilerm -f $filenamemv .sedtmpfile $filename
4.对处理过的文件进行合并,最后生成正确的文件
#! /bin/kshif [ $# != 1 ]then echo "FORMAT: pastefile.sh inputfile !" exit 1;fiif [ ! -f .CUT.OK ];then echo "please cut file,first!" exit 0fifilename=$1# 如果文件中有\t,那么指定paste时的间隔符比如@,所以操作之前要用grep " " filename | wc -l验证#paste -d @ .fileblock_1 \paste .fileblock_1 \ fileblock_2_gmt_date.txt \ .fileblock_3 \ fileblock_4_local_date.txt \ .fileblock_5 \ fileblock_6_settlement_date.txt \ fileblock_7_capture_date.txt \ .fileblock_8 \ fileblock_9_orig_date.txt \ .fileblock_10 > .filebodytmp.txt#sed -e 's/@//g' .filebodytmp.txt > .filenewbody.txtsed -e 's/ //g' .filebodytmp.txt > .filenewbody.txtcat .filehead.txt .filenewbody.txt > ${filename}.newrm -f .fileblock_1 \ fileblock_2_gmt_date.txt \ .fileblock_3 \ fileblock_4_local_date.txt \ .fileblock_5 \ fileblock_6_settlement_date.txt \ fileblock_7_capture_date.txt \ .fileblock_8 \ fileblock_9_orig_date.txt \ .fileblock_10rm -f .filehead.txt .filebody.txt .filenewbody.txt .filebodytmp.txt .CUT.OK
阅读全文
0 0
- 脚本处理大数据文件
- 多线程处理大数据文件
- java 读取大数据文件,处理大数据文件性能比较?
- 大数据文件导入MySql处理方式
- 如何处理大数据文件+录入数据
- phpExcel 读取数据,大数据文件处理方案
- python结合mongodb处理阿里大数据文件
- c-tree数据库的大数据文件处理方式
- TCL脚本数据文件格式
- ftp传输数据文件脚本
- mysql数据文件同步脚本
- 大数据文件上传
- 多线程读取大数据文件
- 二进制存储大数据文件
- 大数据文件分隔符
- Hive导入大数据文件
- JDBC操作大数据文件
- 随机生成大数据文件
- MySql 报ERROR 1292 (22007) 故障
- Hive桶表的操作
- 1565植物大战僵尸
- hdu3410 Passing the Message 单调栈
- 分数拆分(C++)
- 脚本处理大数据文件
- .ascx用户控件
- 堆排序(Heapsort)之Java实现
- mysql联合索引
- Android签名打包、密钥库、密钥全面解析
- solr 6.3 入门(四) (solr facet 高级使用)
- Break,continue以及return有什么区别
- 软件测试面试问答
- Chapter 2