Apr 162008
 

In dealing with some EDI data, advice I came across some data that was invalid

In a file we had a large number of COB segments that looked like this:

COB*U*1234567*01*1

There are supposed to be 3 elements in the COB, treat so I hacked away at it for a while and came up with this command

Find COB^*U^**^*01^*1

With COB*U*00000000000*1

(the ^* means don’t use the expression * to mean all characters, order actually look for * in the data, except where it says ^**^* where there is a *, but consume all data until you find the next *)

But I was not satisfied; I wanted the value from COB02 in the result.

To consume data into a ‘variable’ you use the following syntax

Find COB^*U^*^(*^)^*01^*1

With COB*U*^1*1

the ^(*^) loads whatever is between ^(^) (in this case *) into a variable, and because it is the first one, the output you specify is ^1

So in theory I could have this syntax

Find COB^*U^*^(*^)^*01^*^(*^)

With COB*U*^1*^2

 

The resulting output would be

COB*U*1234567*1