1

I have a text file with protein sequences. I would like to replace all the lowercase letters to upper case letter 'C'. How can I do this with awk?

>1CHE
aHKLbMaHc
>2HV3
PNMRrYnf
>5GH3
LKDeVmqQ

desired output

>1CHE
CHKLCMCHC
>2HV3
PNMRCYCC
>5GH3
LKDCVCCQ
1
  • @SaddamAbuGhaida: I think the OP is just looking to change the protein sequence, not the name of the sequences. tr is probably not appropriate. Although the question is not that well defined...
    – Steve
    Nov 17, 2012 at 10:04

2 Answers 2

6
echo 'changecase' | tr [:lower:] C
1
  • In ZSH, the [:lower:] needs to be quoted.
    – joepd
    Nov 19, 2012 at 22:17
0

I would use sed for this:

sed '/^>/!s/[a-z]/C/g' file.txt

If you'd like the awk, here it is:

awk '!/^>/ { gsub(/[a-z]/, "C") }1' file.txt

Results:

>1CHE
CHKLCMCHC
>2HV3
PNMRCYCC
>5GH3
LKDCVCCQ
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.