我有一个来自MapReduce输出的文件,下面的格式需要使用shell脚本转换为CSV
25-MAY-15
04:20
Client
0000000010
127.0.0.1
PAY
ISO20022
PAIN000
100
1
CUST
API
ABF07
ABC03_LIFE.xml
AFF07/LIFE
100000
Standard Life
================================================
==================================================
AFF07-B000001
2000
ABC Corp
..
BE900000075000027
AFF07-B000002
2000
XYZ corp
..
BE900000075000027
AFF07-B000003
2000
3MM corp
..
BE900000075000027
我需要像下面的CSV格式输出,我想重复文件中的一些值,并添加如下格式的事务ID
25-MAY-15,04:20,Client,0000000010,127.0.0.1,PAY,ISO2002,PAIN000,100,1,CUST,API,ABF07,ABC03_LIFE.xml,AFF07/LIFE,100000,Standard Life, 25-MAY-15,04:20,Client,0000000010,127.0.0.1,PAY,ISO2002,PAIN000,100,1,CUST,API,AFF07-B000001, 2000,ABC Corp,..,BE900000075000027
25-MAY-15,04:20,Client,0000000010,127.0.0.1,PAY,ISO2002,PAIN000,100,1,CUST,API,ABF07,ABC03_LIFE.xml,AFF07/LIFE,100000,Standard Life, 25-MAY-15,04:20,Client,0000000010,127.0.0.1,PAY,ISO2002,PAIN000,100,1,CUST,API,AFF07-B000002,2000,XYZ Corp,..,BE900000075000027
事务ID是AFF07-b00001、AFF07-b00002、AFF07-b00003,它们有不同的值,我在事务ID开始的地方放了一个标记行。在取消标记之前,值应该是重复的,并且需要将transaction ID列与重复值一起添加到上述格式中给出的行之前
我可能需要bashshell脚本,CentOS是linux的风格
当我执行代码时,我得到如下错误
Traceback (most recent call last):
File "abc.py", line 37, in <module>
main()
File "abc.py", line 36, in main
createTxns(fh)
File "abc.py", line 7, in createTxns
first17.append( fh.readLine().rstrip() )
AttributeError: 'file' object has no attribute 'readLine'
有人能帮我吗
这是输入文件和输出格式的正确描述吗?你知道吗
输入文件包括:
每个输出行包括:
所以我们把它翻译成一些Python:
此代码显示如何:
如果您选择python路线,我建议您阅读Input and Output。你知道吗
你只需要把问题分解并尝试一下。对于前17行,在字符串中使用f.readline()和concat。然后使用replace方法获取csv中所需字符串的开头。你知道吗
然后使用split方法将它们分解到列表中。你知道吗
然后在循环中写出文件。使用计数器使你的生活更轻松。首先写出标题字符串
然后在列表中用“,”写下该项。你知道吗
在计数为5时,再次写入带有标题的“\n”,不要忘记重置计数器,以便可以重新开始。你知道吗
试一试,如果你需要更多的助手,请告诉我们。我假设你有一些脚本背景:)祝你好运!!你知道吗
相关问题 更多 >
编程相关推荐