UNIX Split Script

At work we are getting ready to bring one of our facilities into our global standard EDI system. I am not on the EDI team, but as a member of the Application Operations group I manage the rest of their system. This is a big first step for this facility. We will remove their old, ungainly EDI system with it’s maze of scripts and put them on a streamlined, reliable system. But, until we can get them into SAP they will still have an old VMS based ERP system, and on OnBase system that does all the things that their old ERP system can’t do.

In order to accomplish the move we have to detach from the old scripts, and we are doing this by mainly using functionality built into the EDI and OnBase systems. There are a few tasks however that will require a little scripting. For example, the OnBase system needs to be sent a document from the EDI system when purchase orders come in. This is because we use the workflow features in OnBase to track the flow or orders. But, the EDI system can only put out one file that contains all of the orders in a given batch, and OnBase must have one file per order. So, to help out the EDI team I created a simple UNIX script to enable them to post-process the generated report and split it into sepperate files.

The script is general purpose and may have other uses, so I decided to post it here.


# Split a large file into smaller files using a marker line
# Copyright 2008, Christopher Stoll
# ./ source_file_name split_string output_file_name

THISFILE=${1} # The source file (to be split)
THISSPLT=${2} # The string to split on
THISOUTN=${3} # The name of the output files

while read THISLINE
if [ -z "$ISMARKER" ]; then
done < $THISFILE

Comments (newest first)

Ramakrishna Vikash Vanapalli
Hi Christopher,

Thank you for sharing the script.

I have a EDI file with one ISA and multiple ST segments, I am trying to use your script but the output of the script is same as input file.

Below is the command I gave
./ abcd.edi ISA efgh.edi.

Please let me know if I did any thing wrong in giving the search string.

Need your help to resolve this issue

Published: 2008-11-07