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: 
The simplest way is via the following:

```
$ perl -lne '$,=$"; print $_, /a(\d+)/' file
# or this 
$ perl -lpe 's/a(\d+).*\K/ $1/' file

```

```
$ awk '
    match($1, /^a[[:digit:]]+/) &&
    gsub(/$/, FS substr($1, RSTART+1, RLENGTH-1)) ||
  1' file

```

Note:it is safe to use `substr` within `gsub`'s replacement portion since we already made sure it is pure digital.
`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.