Articles

Solved how to append DH lines to each of its DL''s?

February 9, 2013 at 09:00:59
Specs: Windows 7

I have a input file with below data:
DH1|ABC|DEF
DL1|abc|pqr
DL2|mno|rst
DH2|XYZ|MNO
DL1|def|ghi

The output file data must be:
DH1|ABC|DEF|DL1|abc|pqr
DH1|ABC|DEF|DL2|mno|rst
DH2|XYZ|MNO|DL1|def|ghi

Each DH needs to be appended with its corresponding DL's.Can anyone help me out with this?


See More: how to append DH lines to each of its DLs?

Report •


#1
February 11, 2013 at 09:28:21
✔ Best Answer

It looks to me like you are interested in someone doing your homework.

I'll get you started. First, this link shows you how to read a file line by line:

http://www.computing.net/answers/un...

Next, the solution to your problem is lines starting with DL is your base line. It changes every time a new DL line appears. With any other line, to the base line, append a pipe symbol and that line onto the base line and print it out.

The hard part is determining if the line starts with DL. This if statement does that:

   if echo $line| grep "^DH"  > /dev/null
   then
      DHbase=$line
   fi


Report •
Related Solutions


Ask Question