Question: Is there a way to edit a matched pattern and then replace another pattern with the edited pattern?

Input:

```
a11.t
some text here
a06.t
some text here

```

Output:

```
a11.t 11
some text here
a06.t 06
some text here

```

The above example shows the first two digits (matched by first pattern) extracted and placed at the end of the line (second pattern).

In a programming language, I would load the file into a data structure, edit, replace, and write to a new file. But is there a one-line equivalent?

Trial:

```
sed 's/\(a[0-9][0-9].*\)/& \1/I' stack.fa | sed -e 's#a##g2' -e 's#\.\w##g2'

```

Trial output:

```
a11.t 11
some text here
a06.t 06
some text here

```

Obviously the trial works, but is there a more robust way? Further, is there another text processing language this could done in more easily?

Answer: 
Although it has fallen out of fashion, few languages can match perl for text processing. For instance:

1. Assume only one set of numbers, copy to the end of the line:

```
 $ perl -pe 's/.*?a(\d+).*/$& $1/' file
 a11.t 11
 some text here
 a06.t 06
 some text here

```
2. Multiple sets of numbers, add both to the end

```
 $ cat file
 a11.t
 some text here
 a06.t
 some text here
 a11.t a54.g

 $ perl -pe '@nums=(/a(\d+)/g); s/$/ @nums/' file
 a11.t 11
 some text here 
 a06.t 06
 some text here 
 a11.t a54.g 11 54

```
`perl` or `sed` are the way to go, but just for the sake of completion, a re-write of @PraveeenKumarBS' python snippet's first version, using module `re`'s concept of matched "group":

```
#!/usr/bin/python3
import re
pattern = re.compile(r'(\d{2})')
with open('data', 'r') as file:
    for line in file:
        match = re.search(pattern, line)
        if match:
            print(line.rstrip('\n'), match.group(1))
        else:
            print(line.rstrip('\n'))

```

If as OP seems to imply the pattern to look for always includes a first letter, just make the pattern: `pattern = re.compile(r'[a-zA-Z](\d{2})')`.

The corner(?) case of more than one match per line (as remarked by @terdon) is also easily dealt with using a new match expression `match = re.finditer(pattern, line)` and a modified `print` instruction.