We are parsing some large EDI files that do not contain CR/LF. However, they do have ~ (tilde) as a segment delimiter.
I am trying to extract the control record for the file and the last bytes of my 120 MB file look something like this:
~REF*1L*0711882~SE*62300*39093~GE*1*500001242~IEA*1*500001241~
There is only one control record in the file and it always starts with ~SE.
So, is there an easy way using standard Unix cut, awk, grep, etc. tools to cut this file to get the SE*62300*39093 segment, other than converting the ~ to CRLF and tailing the last three lines of the file?
Disclaimer:
I am not a Unix guru, so the answer may be obvious to an experienced user. Also, I have no control over the file format.

~to newlines and tailing the last 3 lines of the file. If the file is known to not already contain newlines then this does not introduce any ambiguity into the format, and frankly it's the best way to massage the file into a format that makes it easy for all those line-based tools to work with. – Celada Jan 31 at 20:11tail. No need to parse it all. Something liketail edi_file | grep ~SE | cut -d'~' -f 3(where edi_file is the name of your large file) (Disclaimer: Example only works if the required field is in field #3 (delimited by ~'s as by -d`~`. That might need adjusting. Can we get a larger size example of the input file? – Hennes Jan 31 at 20:16tail --bytes=5000 ding... and then you hope that the last 5000 bytes are enough to encompass the 3 lines that you need. – Celada Jan 31 at 20:33