Hi, radoulov:
Using your code as a foundation, making some remodeling, I got my solutions to solve my own problem.
I intended to interleave and merge my own 2 data files like below.
I realized they are not in array, so I cannot take any advantage of the pseudo index feature of awk.
But I took full advantage of its NR/FNR feature to build a traditional array and get my work done.
My code works for me pretty well except there is tiny imperfection at the very beginning of the output. I can manually fix it in a snap. Its not for commercial use, just for my own hobby, so it's good enough for me for now.
I need to thank you again. Without your support, I couldn't have finished what I thought of so quick. I wish you have a happy holiday.
regards,
== file_E
1
00:00:01,400 --> 00:00:10,300
In the air war of Vietnam, one day stands out among all the rest.
2
00:00:10,300 --> 00:00:21,666
May 10, 1972, the full fury of American air power is unleashed on North Vietnam.
3
00:00:22,600 --> 00:00:30,433
More Vietnamese MiGs are shot down on this day than on any other day of the war.
== file_C
1
00:00:01,400 --> 00:00:10,300
2
00:00:10,300 --> 00:00:21,666
1972510
3
00:00:22,600 --> 00:00:30,433
== awk code
awk > "SRT" '{if(NR==FNR && length($0)> 0)
{#now read file_E into f2
f2[FNR]=$0}
else if(length($0)> 0)
{#now read in file_C, because NR!=FNR
{if(FNR==1){end=NR-1}}
{for (i=1; i <= end; i++)
if( $0==f2){print $0; next}
}
# {printf "|%d| --> |%s|\n", FNR, f2[FNR]}
printf "%s\n",f2[FNR];
printf "%s\n\n",$0
}
}' file_E file_C #
== output:
1
00:00:01,400 --> 00:00:10,300
In the air war of Vietnam, one day stands out among all the rest.
2
00:00:10,300 --> 00:00:21,666
May 10, 1972, the full fury of American air power is unleashed on North Vietnam.
1972510
3
00:00:22,600 --> 00:00:30,433
More Vietnamese MiGs are shot down on this day than on any other day of the war.
p.s.
The file is the subtitles of a History Channel program Dogfights. The 2nd data file is in Chinese. Chinese speaking people are not necessary from China. In Asia, there are 3 countries use Chinese as their official language.