Transcribe DNA to RNA with tr

Foundational Bash Foundations Bash tr sed Character Substitution
Significance:

Character-level substitution is a surprisingly deep Unix skill. Transcription is the
simplest possible example — swap every T for a U — but the same tool does case conversion, complement
generation, and character deletion. Once you have used tr to build a reverse complement in a single
pipeline you understand why command-line bioinformatics survived the arrival of Python.

Statement

A single DNA sequence arrives on standard input.

Transcribe it into RNA by replacing every occurrence of T with U, leaving all other characters
unchanged.

Print the resulting RNA sequence on one line.

Input — read from standard input
Variable Type Description
dna
line 1
str The DNA sequence to transcribe
1 <= len(dna) <= 5000, uppercase A, C, G, T only

These variables are already read for you in the starter code on the right.

Output

str the transcribed RNA sequence on one line

Sample Cases
Sample 1
Input
GATGGAACTTGACTACGTAACGTTTTT
Expected Output
GAUGGAACUUGACUACGUAACGUUUUU
Every thymine becomes uracil; all other bases are untouched.
Sample 2
Input
ACGT
Expected Output
ACGU
A minimal four-base sequence.

Submit also runs your code against 3 hidden test cases. Hidden inputs are never shown — if one fails you'll get its number and a description of the mismatch, not the data.

Constraints
  • Only uppercase T is replaced; no other character changes
  • The output has exactly the same length as the input
  • Input contains only uppercase A, C, G, T
  • Solutions must read standard input and write to standard output only
Further Reading
  • tr 'T' 'U' performs the substitution character by character with no pattern matching overhead.
  • sed 's/T/U/g' does the same job; note the g flag, without which only the first T per line changes.
  • tr reads standard input directly, so no explicit loop is needed.

Judged against GNU Bash 5.1.0.


My Notes
Log in to save personal notes.
Console output will appear here when you click Run Code or Submit...
Expected: dna (str)
Next Problem
Sequence Sanitiser