I'd always appreciate all helps from this website. I would like to relocate strings based on the index number from an index file.
Index numbers are shown on the first column in the index file (index.txt) and I would like to relocate "path" based on index numbers. Paths are placed in the same row if the index number is the same. For example, there are two zeros so path_sparc_ifu_dec_in_3826 is placed on the first row and path_sparc_ifu_dec_in_4349 is placed on the first row and next to path_sparc_ifu_dec_in_3826.
index.txt:
0 path_sparc_ifu_dec_in_3826 str DR - -
0 path_sparc_ifu_dec_in_4349 stf DR - -
1 path_sparc_ifu_dec_in_2374 stf DR - -
1 path_sparc_ifu_dec_in_4011 stf DR - -
2 path_sparc_ifu_dec_in_3078 stf DR - -
However, strings are written in another file (source.txt) and each "path" has four lines of strings.
My idea is that (1)combining two files first and (2) relocate path info using the index number, but I don't know how to do this work. Probably, sed/awk is an appropriate language.
I have changed a server to run this code and get the desired result. One quick question is how to insert a tab between strings. I tried print P[i, j]"\t" and print "\t"P[i, j] , but did not work.
In post #1 in this thread, you showed us index.txt and source.txt files that had leading spaces on every line in both files. To get the output you are showing above, we have to assume that those spaces do not appear in source.txt .
If you want a tab in the output separating the text from various lines in source.txt , change the line in your code marked in red above in your script from: