I have 0.txt and 1.txt files. In the 0.txt file the content is as shown below:
[{A,B,C},{D,E,F}][{G,H,I}]
The contents of the 1.txt file is as shown below:
[{A,B,C},{D,E,F}]
[{G,H,I}]
That is, the difference between 0.txt and 1.txt is that in the 1.txt file there is a line break.
What I desire is to be able to extract all the text between '[' and ']' in your NTH OCCURRENCE using awk -F'[][]' -v n=2 '{ print $(2*n) }' 1.txt > 2.txt (Extract the text between the nth occurrence of square brackets), this for text formatting shown in 1.txt file.
So my wishes corresponding to n=2 would be 2.txt as shown below:
{G,H,I}
To do so, at first, I have been able to do this just for text formatting when there is no line break as shown at 0.txt.
I need to know how to extract the text between '[' and ']' when there is line break as shown at 1.txt.
The output of awk -F'[][]' -v n=2 '{ print $(2*n) }' 1.txt > 2.txt has been all the content of 0.txt (except Square Brackets) instead of only {G,H,I}. That is, the 2.txt content is as below:
{A,B,C},{D,E,F}
{G,H,I}
Edit Update 01:
The solution must have the same effect for a third input file as below, considering the third occurrence, that is, [{J, K, L}]. So the expected exit should be {J, K, L}.
[{A,B,C},{D,E,F}]
[{G,H,I}]
[{J,K,L}]
For all purposes for the nth occurrence of [{x, y, z, ..}] (respected the condition of no text out of [ and ], and no blank line) Any solution given should extract to the Output file exactly {x, y, z, ..}.