Avatar of NAEDI2
NAEDI2
Flag for United States of America

asked on 

I need a Regex for SED string replace across multiple ascii files

I need SED to replace a string across multiple ASCII text files based on a regex pattern.  These files are descriptions of EDI file formats with records described in this format:

E2EDPT2 {  DELIMITER="\x0a" }:
    E2EDPT2_SEGNAM		# Segment E2EDPT2
    E2EDPT2_MANDT
    E2EDPT2_DOCNUM
    E2EDPT2_SEGNUM
    E2EDPT2_PSGNUM
    E2EDPT2_HLEVEL
    E2EDPT2_TDLINE
    E2EDPT2_TDFORMAT
    rest[0:"^\x0a"]*
;

E2EDPT2_SEGNAM: STRINGA { LENGTH=30, DEFAULT="E2EDPT2001                    " };
E2EDPT2_MANDT: NSTRINGA { LENGTH=3 };
E2EDPT2_DOCNUM: STRINGA { LENGTH=16 };
E2EDPT2_SEGNUM: STRINGA { LENGTH=6 };
E2EDPT2_PSGNUM: STRINGA { LENGTH=6 };
E2EDPT2_HLEVEL: STRINGA { LENGTH=2 };
E2EDPT2_TDLINE: STRINGA { LENGTH=70, MISSVALUE="                                                                      " };
E2EDPT2_TDFORMAT: STRINGA { LENGTH=2, MISSVALUE="  " };

Open in new window


What I need to do is replace the occurrences of fields like "E2EDPT2_SEGNUM" above with plain "SEGNUM".  All record types will have this field and I want to lose the record name part leaving just the fieldname SEGNUM.  The recordname part will always begin with a fixed length "E2EDXXX-".  What is the correct regular expression to get this done?
Regular Expressions* PERL Regular Expressions (regex)

Avatar of undefined
Last Comment
Bill Prew

8/22/2022 - Mon