读入分组后写成多个文件

【问题】

i have a text file with name text.txt :

09102306614,2,104
09106148895,2,104
09102567410,3,104
,...


09122586173,2,104
09126413664,2,104
09125554671,3,104

,...

i want read text1.txt with java and create text1.txt from first column data where foure character of first number like with together for sample, text1.txt included :

0910*******
0910*******
0910*******
,...

and text2.txt included :

0912*******
0912*******
0912*******
,...

thank you

【回答】

       取出第1个字段,按前4个字符分组,每组各写一个文件。Java写起来很繁琐,但用SPL就容易多了,也可以集成进Java(参考Java 如何调用 SPL 脚本)。

A
1=file("text.txt").import@ic(#1:string)
2=A1.group(left(~,4)).run(file("d:\\text"+string(#)+".txt").export(~))

A1:只读入第1列,强制转换成字符串。

A2:按照前4个字符分组,并将各组分别写入不同文件。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值