I need insert a new line with specific content after find a pattern in text1 file with shell.
I have a file text_file_1.txt with this content:
aaaaaa
bbbbbb
patternrefrefref
cccccc
aaaaaa
patternasdasd
pattern
zzzzzz
and a text_file_2.txt with this content:
111111
333333
555555
and I need insert the first line of text_file_2.txt (that is, 111111) when I find the first occurrence of "pattern" of text_file_1.txt and 333333 when I find the second occurrence of "pattern (always pattern)...
Final result will be:
aaaaaa
bbbbbb
pattern_refrefref
111111
cccccc
aaaaaa
pattern_asdasd
3333333
pattern
555555
zzzzzz
I found how to insert a new line with a new text after a pattern but always insert the same text, I don't need that.
NR==FNR), though I guess it could be possible to do insedas well.