I have a text file (FILE_A.txt) with this content:
Content1
Content2
Content3
And other text file (FILE_B.txt) with this content:
A[#]
B[#]
C[#]
I would like to combine FILE_A.txt and FILE_B.txt in other file (FILE_C.txt) in this way:
A[Content1]
B[Content2]
C[Content3]
How could I make this using bash shell in linux (sed, cut, grep, etc)?
Here we go.
How does this work?
NR==FNR– causes the following statements to be run if the record number matches the FILE record number – that is, we are currently reading only the firs tfile.{a[NR]=$0;next;}– Store values from the first file in an array.sub(/#/,a[FNR])– Once we’re in the second file, substitute#for the matching value stored from the first file. Note that this isn’t inside curly brackets, so it’s being evaluated as a condition. If thesub()statement succeeds, the current line is printed.