输入1:create external table db.emp(id int,name string)
row formatted fields terminated by ','
location 'hadfs:.../';
create external table db.emp1(id int,name string)
row formatted fields terminated by ','
location 'hadfs:.../';
输入2:create table db.emp(id int,name string)
location 'hadfs:.../';;
create table db.emp1(id int,name string)
location 'hadfs:.../';
再查询输出:create external table db.emp(id int,name string)
row formatted fields terminated by ','
location 'hadfs:.../';
create table db.emp(id int,name string)
location 'hadfs:.../';
这两个文件存储在file1.hql下create external table db.emp1(id int,name string)
row formatted fields terminated by ','
location 'hadfs:.../';
create table db.emp1(id int,name string)
location 'hadfs:.../';
这两个文件存储在file2.hql下,以此类推filenames = ['in1.txt', 'in2.txt']
with open('result.txt', 'w') as outfile:
for fname in filenames:
with open(fname) as infile:
content = infile.read().replace('\n', '')
outfile.write(content)
但是我没有得到正确的输出。请给我一个提示如何做到这一点。
使用此代码时,我得到的输出不正确
我试过密码import re
import sys
f = open ('text.txt','r')
fout = open ('hql.txt','w')
text = f.read()
fout = "hql.txt"
fout = open('hql.txt','w')
for item in re.findall(r'CREATE[^;]*;',text):
print >>fout, re.search(r'(?<=\.)\w+',item).group()+'.hql'
print >>fout,(item)
f.close()
fout.close()
此代码的o/p为:emp.hql
create external table db.emp(id int,name string)
row formatted fields terminated by ','
location 'hadfs:.../';
emp1.hql
create external table db.emp(id int,name string)
row formatted fields terminated by ','
location 'hadfs:.../';
它将向input1和input2文件生成这种输出。
现在我需要继续create external table db.emp(id int,name string)
row formatted fields terminated by ','
location 'hadfs:.../';
create table db.emp(id int,name string)
location 'hadfs:.../';
并以电磁脉冲hql等等。你知道吗