Hello every,
I am stuck in a problem. I have file like this. I want to add the fifth field of the match pattern line above the lines starting with "# @D". The delimiter is "|"
eg
>
# @D0.00016870300|0.05501020000|12876|12934|3||Qp||Pleistocene||"3 Qp Pleistocene"|Q
# @P
-82.153320080911939 24.544923921489307
-82.157188580915545 24.547376421491592
-82.161033580919124 24.550294921494309
-82.161888080919908 24.554044921497802
-82.161247080919324 24.557744921501246
-82.159134080917354 24.561397421504651
-82.156906080915277 24.56450292150754
-82.156524580914919 24.565032921508035
-82.152671580911331 24.562114921505319
-82.151329080910074 24.558347921501809
-82.152969580911616 24.55421442149796
-82.149078580907997 24.552226921496107
-82.148239080907203 24.548477421492617
-82.149360580908251 24.544790421489182
-82.153320080911939 24.544923921489307
>
# @D0.00123462000|0.23518800000|12875|12933|12||Qp||Pleistocene||"3 Qp Pleistocene"|Q
# @P
-81.750862080537118 24.558242921501712
-81.754951580540933 24.55513742149882
-81.758926580544625 24.554820921498525
-81.764396580549715 24.554092421497849
-81.768371580553435 24.553773921497552
-81.776359580560865 24.552207921496091
-81.780334580564571 24.551889421495794
-81.784843580568776 24.550657421494648
Expected output
>
3
# @D0.00016870300|0.05501020000|12876|12934|3||Qp||Pleistocene||"3 Qp Pleistocene"|Q
# @P
-82.153320080911939 24.544923921489307
-82.157188580915545 24.547376421491592
-82.161033580919124 24.550294921494309
-82.161888080919908 24.554044921497802
-82.161247080919324 24.557744921501246
-82.159134080917354 24.561397421504651
-82.156906080915277 24.56450292150754
-82.156524580914919 24.565032921508035
-82.152671580911331 24.562114921505319
-82.151329080910074 24.558347921501809
-82.152969580911616 24.55421442149796
-82.149078580907997 24.552226921496107
-82.148239080907203 24.548477421492617
-82.149360580908251 24.544790421489182
-82.153320080911939 24.544923921489307
>
12
# @D0.00123462000|0.23518800000|12875|12933|12||Qp||Pleistocene||"3 Qp Pleistocene"|Q
# @P
-81.750862080537118 24.558242921501712
-81.754951580540933 24.55513742149882
-81.758926580544625 24.554820921498525
-81.764396580549715 24.554092421497849
-81.768371580553435 24.553773921497552
-81.776359580560865 24.552207921496091
-81.780334580564571 24.551889421495794
-81.784843580568776 24.550657421494648
I tried something like this
awk -v pat="# @D" '{a[NR]=$0;}END{for(i=1;i<=NR;i++){if(a ~ pat ){print a"\n" a;}else{print a;}}}' tst_geo.gmt >output.txt
I feel like I am almost there, but just can't figure out how to print certain filed of the matched line.
Please help