Awk or Sed: File Annotation

Posted by lukmac on Stack Overflow See other posts from Stack Overflow or by lukmac
Published on 2011-01-05T21:30:06Z Indexed on 2011/01/05 21:53 UTC
Read the original article Hit count: 160

Filed under:
|

Hallo, my SO friend, my question is:

Specification: annotate the fields of FILE_2 to the corresponding position of FILE_1.
A field is marked, and hence identified, by a delimiter pair.

I did this job in python before I knew awk and sed, with a couple hundred lines of code. Now I want to see how powerful and efficient awk and sed can be. Show me some masterpiece of awk or sed, please!

The delimiter pairs can be configured in FILE_3, but let's assume the first delimiter in a pair is
'Marker (number i) start', the other one is
'Marker (number i) done'

Example:
|-----------------FILE_1------------------|
text text text
text blabla
Marker_1_start
Marker_1_done
any text
in between blabla
Marker_2_start
Marker_2_done
text text

|-----------------FILE_2------------------|
Marker_1_start
11
1111
Marker_1_done
Marker_2_start
2222
22
Marker_2_done

Expected Output:
|-----------------FILE_Out------------------|
text text text
text blabla
Marker_1_start
11
1111
Marker_1_done
any text
in between blabla
Marker_2_start
2222
22
Marker_2_done
text text

© Stack Overflow or respective owner

Related posts about sed

Related posts about awk