Îxtract data in between paratheses and append at the end of the line
<p>File.txt:</p>

<pre><code>first_name NVARCHAR2(15) NOT NULL,
middle_name NVARCHAR2(20) NOT NULL,
last_name NVARCHAR2(11) NOT NULL,

output i need:-&gt;output.txt
first_name NVARCHAR2(15) NOT NULL,15
middle_name NVARCHAR2(20) NOT NULL,20
last_name NVARCHAR2(11) NOT NULL,11
</code></pre>

<p>How can I extract data in <code>File.txt</code> between paratheses and append at the end of the line?</p>

<p>Use regex - something like:</p>

<pre><code>import re
for line in input:
    m=re.search('\((\d+)\)',line)
    output.write(line.rstrip('\n')+m.group(1)+'\n')
</code></pre>

<p>The search content should match what you are looking for (<code>\d+</code> in my example - matches any number). If you expect more then one parentheses in a sentence then you should give some more info. But in general, to extract a part of a match to your regex, use parentheses around what you wish to extract, and use <code>group(index)</code> on the retrieved "match item" (<code>m</code> in the example) - where <code>index</code> is the index of the parentheses you put in your regex that their content you wish to retrieve (and 0 means the entire match).</p>

<p>For example:</p>

<pre><code>m=re.search('a(.)c(.)e','abcde')
m.group(0)
'abcde'
m.group(1)
'b'
m.group(2)
'd'
</code></pre>

python python-3.x