# Replace lowercase characters with -

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

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 - .

• Thaks. I did try to do it without making new copy, but this works. – robinj Nov 7 '18 at 12:48
• you can pipe this to vcfutils.pl vcf2fq output. – arupgsh Nov 9 '18 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:]' '-'