<p>You could try it with <code>sed</code>.<br>
Replace all lower-case chars with <code>-</code> in lines not starting with <code>&gt;</code>:</p>

<pre><code>sed -e '/^&gt;/!s/[a-z]/-/g' in.fa
</code></pre>

CC BY-SA 4.0
2018-11-06T10:30:03.637Z
2018-11-06T10:57:20.960Z
2018-11-06T10:57:20.960Z
Peter Menzel
<p>You can also use this solution where <strong>tr</strong> command from linux can solve your problem:</p>

<p><code>tail -n +2  in.fna | tr '[:lower:]' '-'</code></p>

CC BY-SA 4.0
2018-11-06T12:09:06.477Z
2018-11-06T12:09:06.477Z
Ammar Sabir Cheema
<p>The following <code>sed</code> command will do the trick.</p>

<p><code>sed -e '/^[^&gt;]/ s/[a-z]/\-/g' in.fna &gt; out.fna</code></p>

<p>Lines starting with <code>&gt;</code> will be escaped and the lowercase characters will be replaced with <code>-</code> .</p>

CC BY-SA 4.0
2018-11-07T12:48:23.647Z
Thaks. I did try to do it without making new copy, but this works.
robinj
CC BY-SA 4.0
2018-11-09T05:31:00.750Z
you can pipe this to `vcfutils.pl vcf2fq` output.
arup
CC BY-SA 4.0
2018-11-06T10:26:20.770Z
2018-11-06T10:26:20.770Z
arup
<p>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:</p>

<pre><code>awk 'BEGIN{FS=" "}{if(!/&gt;/){print toupper(<span class="math-container">$0)}else{print $</span>1}}' in.fna &gt; out.fna
</code></pre>

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

<bash><shell>
Replace lowercase characters with -
# Replace lowercase characters with -

(Asked by: username_0 on 2018-11-06)

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

**Tags:** bash, shell

---

## 3 answers

### Answer by username_3 on 2018-11-06. Score: 4 | Accepted answer

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

> **Comments:**
> **username_0**: Thaks. I did try to do it without making new copy, but this works.  
> **username_3**: you can pipe this to `vcfutils.pl vcf2fq` output.  

---

### Answer by username_1 on 2018-11-06. Score: 3

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


---

### Answer by username_2 on 2018-11-06. Score: 1

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

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


---

