bash - dealing with special characters in filenames
<p>I am using bash shell and am working with the human reference genome GRCh38. I have a list of files in a directory, one file for each chromosome. Now I need to search the list of file names. Seems trivial but the file names inconveniently have special characters. Example:</p>

<pre><code>ls -1 ../GRCh38_chromosomes/
</code></pre>

<p>outputs the contents of the directory:</p>

<pre><code>…
HLA-DRB1*13:01:01?HLA00797_13935_bp.fa
HLA-DRB1*13:02:01?HLA00798_13941_bp.fa
HLA-DRB1*14:05:01?HLA00837_13933_bp.fa
HLA-DRB1*14:54:01?HLA02371_13936_bp.fa
HLA-DRB1*15:01:01:01?HLA00865_11080_bp.fa
HLA-DRB1*15:01:01:02?HLA03453_11571_bp.fa
…
</code></pre>

<p>Im having difficulty searching for a particular filename (from withing a script) because the “?” character in particular seems to get replaced by “\t”. Example:</p>

<pre><code>ls -1 ../GRCh38_chromosomes/ | perl -ne ' print $_; '
</code></pre>

<p>I expect the same output but instead get:</p>

<pre><code>…
HLA-DRB1*13:01:01   HLA00797_13935_bp.fa
HLA-DRB1*13:02:01   HLA00798_13941_bp.fa
HLA-DRB1*14:05:01   HLA00837_13933_bp.fa
HLA-DRB1*14:54:01   HLA02371_13936_bp.fa
HLA-DRB1*15:01:01:01    HLA00865_11080_bp.fa
HLA-DRB1*15:01:01:02    HLA03453_11571_bp.fa
…
</code></pre>

<p>this is causing me a headache when I try a search such as</p>

<pre><code>ls -1 ../GRCh38_chromosomes/ | perl -ne ' if ( $_ =~ /^\QHLA-DRB1*15:01:01:02?\E/ ) { print $_; } '
</code></pre>

<p>which should output:</p>

<pre><code>HLA-DRB1*15:01:01:02?HLA03453_11571_bp.fa
</code></pre>

<p>but instead finds nothing. Ive also tried awk with the same problem and am wondering why they put special characters in the chromosome names for GRCh38? Any ideas how to deal with these problem characters?</p>