I have an output from vcfutils.pl vcf2fq with specified minimal depth, and it means that nucleotides with not enough depth are lowercase. I would like to change them to gaps. I could do it in higher language but I would like to know the solution in bash. I have found simple solution to replace all lowercase to uppercase:

awk 'BEGIN{FS=" "}{if(!/>/){print toupper($0)}else{print $1}}' in.fna > out.fna

but I would like to replace lowercase with -. The first row need to be omitted. Could you help me? Thanks


3 Answers 3


The following sed command will do the trick.

sed -e '/^[^>]/ s/[a-z]/\-/g' in.fna > out.fna

Lines starting with > will be escaped and the lowercase characters will be replaced with - .

  • $\begingroup$ Thaks. I did try to do it without making new copy, but this works. $\endgroup$
    – robinj
    Commented Nov 7, 2018 at 12:48
  • $\begingroup$ you can pipe this to vcfutils.pl vcf2fq output. $\endgroup$
    – arup
    Commented Nov 9, 2018 at 5:31

You could try it with sed.
Replace all lower-case chars with - in lines not starting with >:

sed -e '/^>/!s/[a-z]/-/g' in.fa

You can also use this solution where tr command from linux can solve your problem:

tail -n +2 in.fna | tr '[:lower:]' '-'


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.