How can I change 0123 in ACTG with tr or Perl?

I have a file with this list:

100
101
102
103

What I want to do is replace all 0 with A, 1 with C, 2 with G, 3 with T. So we hope to get

CAA
CAC
CAG
CAT
+3
source share
5 answers

You yourself worked out the answer. Simply:

tr 0123 ACGT <input_file >output_file

or

echo 2033010 | tr 0123 ACGT
+10
source

Here:

perl -p -e 'tr/0123/ACGT/'

Verification:

$ perl -p -e 'tr/0123/ACGT/' <~/input
CAA
CAC
CAG
CAT
+7
source

:

sed 'y/0123/ACGT/' file
+7
$ echo 3210 | tr 0123 ACGT
TGCA

- , tr 1:1 . , , 0 A, 1 C, 2 G, 3 - T.

+4
   $ awk -vFS="" 'BEGIN{_["1"]="C";_["2"]="G";_["3"]="T";_["0"]="A"}{for(i=1;i<=NF;i++){printf _[$i]}print ""}' file
    CAA
    CAC
    CAG
    CAT
+2

Source: https://habr.com/ru/post/1742048/


All Articles