对多个 txt 做 JOIN 关联

【问题】

Need a help. I have a big text file which has location data (represented numerically) and needs to be replaced with its corresponding location. These two files are separate text files.

Could you help with the java utility on how to replace the numeric values in one file using location values for the other.

Below is an example of the contents of file 1 and file 2. File 1 has numeric data and text. The numeric data in the first column needs to be replaced with the corresponding entry from file2. Thus, the file 1 needs to be looped for each entry in file 2.
Text File1:

19922973 @Uniquehope was good

Test File2:

19922973 Chicago, IL

Need to replace 19922973 with Chciago, IL. Please provide your inputs.

Thanks Saurabh

【回答】

这个类似于 SQL 语句中的 join,但 JAVA 本身不提供结构化计算函数,实现起来非常麻烦,如果文件太大而无法读入内存,代码将更加复杂。可以考虑用集算器辅助 JAVA 实现文本文件的连接,SPL 代码如下:

A
1=file("D:\\file1.txt").import()
2=file("D:\\file2.txt").import()
3=join@1(A1:f1,_1; A2:f2,_1)
4=A3.new(f2._2,f1._2)
5=file("D:\\result.txt").export(A4)

A1/A2:分别从文本文件中读取数据

A3:函数 join 执行连接运算,并将两个表改名为 f1 和 f2。其中函数选项 @1 表示左连接,即例子中的要求:将 A2 对齐到 A1 中

A4:从连接的表中取得需要的字段,组成新的序表

A5:将 A4 的数据输出到新的文件

写好的脚本如何在 JAVA 应用程序中调用,可以参考Java 如何调用 SPL 脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值