How to get matching pattern along with ID in a single command in grep?
Use this Perl one-liner:
perl -lne '$id = $1 if /^&gt;(.+)/; ($m) = /(CC[GT]AAA[GC][AC]TT[GC])/; print join &quot;\t&quot;, $id, $m if $m;' input.fasta

The Perl one-liner uses these command line flags:
-e : Tells Perl to look for code in-line, instead of in a file.
-n : Loop over the input one line at a time, assigning it to $_ by default.
-l : Strip the input line separator (&quot;\n&quot; on *NIX by default) before executing the code in-line, and append it when printing.
SEE ALSO:
perldoc perlrun: how to execute the Perl interpreter: command line switches