tried to do with sort, but of no help. I couldn't actually figure out the correct way to do it. so could someone please tell me in more precise on how to proceed with sort.
Based on what? You haven't given any real information as to what you're trying to do, so how can you expect anybody to tell you how to do it?
Show a good example of your input records (relevant fields only) and what you expect for output. Explain the "rules" for getting from input to output. Give the RECFM and LRECL of the input file. Give the starting position, length and format of the relevant fields.