Replace line with found unknown pattern

Hi,

I have a file with the following content:

---------
a 3242 tc_5 gdfg4
random text
a 3242 tc_6 gdfg4
random text
a 3242 tc_7 gdfg4
random text
a 3242 tc_4 gdfg4
---------

I want to replace the lines containing tc_? (tc_5, tc_6 etc. even with unknown numbers) with the found pattern (including the unknown numbers). The result file should look like:

---------
tc_5
random text
tc_6
random text
tc_7
random text
tc_4
---------

Thanks in advance.

Joas

$ ruby -ne '$_=$_.scan(/(tc_\d+)/)[0] if $_["tc_"];puts $_' file

Thank you for your input but on the target machine we don't have ruby installed and I can't do that. Is it possible to solve with sed or awk instead?

Thanks

perl -i -pe 's/(.*?)(tc_\d*)(.*)/$2/' input_file
sed 's/.*\(tc_[0-9]*\) .*/\1/' file