Telling grep to treat N as [ATCG] Okay so I'm using grep to try and get a preview of some trimming operations that are not going as expected..
Lets say that my sequence in the FastQ file is: ATNGCNATCG
What I want to do is..
grep &quot;ATCGCTATCG&quot; my.fastq
..and match the sequence given above
Surely there is some way or some existing tool that I can use besides doing:
grep &quot;[A|N][T|N][C|N][G|N][C|N]...etc.&quot;
If you want to stick to grep, use a scripting language such as Perl to generate the regex programmatically. For example:
perl -le 'print join &quot;&quot;, map &quot;[${_}N]&quot;, split //, $ARGV[0];' ATCGCTATCG 

Prints:
[AN][TN][CN][GN][CN][TN][AN][TN][CN][GN]

You can use it in grep like so:
grep '[AN][TN][CN][GN][CN][TN][AN][TN][CN][GN]' &lt;&lt;&lt; ATNGCNATCG

Prints:
ATNGCNATCG

If that works for you, you could make it into a little bash function that also runs the grep. Add these lines to your ~/.bashrc:
grepN(){
    seq=&quot;$1&quot;
    file=&quot;$2&quot;
    pattern=$(perl -le 'print join &quot;&quot;, map &quot;[${_}N]&quot;, split //, $ARGV[0];' &quot;$seq&quot;)
    grep &quot;$pattern&quot; &quot;$file&quot;
}

You can now run
grepN ATCGCTATCG my.fastq

Of course, this is not a good idea since the sequence might be in different lines, but that's what you were doing originally.