I've been working on a script (/bin/sh) in which I have requested and received help here (in which I am very grateful for!). The client has modified their requirements (a tad), so without messing up the script to much, I come once again for assistance.
Here are the file.dat contents:
ABC1 012345 header
ABC2 7890-000
ABC3 012345 Header Table <= Need this line in report
ABC4
ABC5 593.0000 587.4800
ABC5 593.5000 587.6580 <=Duplicate to be put in file.out
ABC5 593.5000 587.6580
ABC5 594.0000 588.0971
ABC5 594.5000 588.5361
ABC1 67890 header
ABC2 1234-0001
ABC3 67890 Header Table <= Need this line in report
ABC4
ABC5 594.5000 588.5361
ABC5 601.0000 594.1603
ABC5 601.5000 594.6121
ABC5 602.0000 595.0642
ABC5 602.0000 595.0642 <=Duplicate to be put in file.out
My current code will find the section header (ABC1) and the duplicates (ABC5) in that section and output that information into another file.
New client requirement: I need to add the �ABC3� line into the report
Needed Output file (file.out):
ABC1 012345 header
ABC3 012345 Header Table <= Need this line added per section
ABC5 593.5000 587.6580
ABC1 67890 header
ABC3 67890 Header Table <= Need this line added per section
ABC5 602.0000 595.0642
Here is my current code:
# This will find the start of a section ABC1 and print the
# header and duplicate lines data into a file.out
awk 'NF==3 && /ABC1/; $0!=s{s=$0;next}1' file.dat > file.out
Any suggestions?