0

我有一个包含很多 HL7 段的巨大文件。它必须分成 1000 个(或更多)较小的文件。因为它有 HL7 数据,所以有一个模式(逻辑)可以通过。每个数据块都以“MSH|”开头 并在下一段以“MSH|”开头时结束。

该脚本必须基于 Windows (cmd) 或 VBS,因为我无法在该机器上安装任何软件。

文件结构:

MSH|abc|123|....
s2|sdsd|2323|
...
..
MSH|ns|43|...
...
..
.. 
MSH|sdfns|4343|...
...
..
asds|sds

MSH|sfns|3|...
...
..
as|ss

上例中的文件,必须拆分为 2 或 3 个文件。此外,这些文件来自 UNIX,因此换行符必须与源文件中的一样。

有什么帮助吗?

4

2 回答 2

2

这是一个示例脚本,我用来根据数据文件将大型 hl7 文件解析为具有新文件名的单独文件。使用不需要安装的 REBOL,即。核心版本不做任何注册表项。

我有一个更通用的版本,它扫描传入目录并将它们拆分为单个文件,然后等待下一个文件到达。

Rebol [
    file: %split-hl7.r
    author: "Graham Chiu"
    date: 17-Feb-2010
    purpose: {split HL7 messages into single messages}
]

fn: %05112010_0730.dat
outdir: %05112010_0730/

if not exists? outdir [
    make-dir outdir
]

data: read fn
cnt: 0
filename: join copy/part form fn -4 + length? form fn "-"
separator: rejoin [ newline "MSH"]
parse/all data [
    some [
        [ copy result to separator | copy result to end ]
        (
            write to-file rejoin [ outdir filename cnt ".txt" ] result
            print "Got result"
            ?? result
            cnt: cnt + 1
        )
        1 skip
    ]
]
于 2010-07-22T10:59:16.177 回答
1

HL7 有很多段 - 我假设您知道您的文件只有 MSH 段。那么,您是否尝试过为字符串“(newline)MSH|”解析文件?只需保留一个正在运行的缓冲区并在它变得太大时将其转储到输出文件中。

于 2010-06-30T19:24:32.813 回答