grep
and find
are two utilities for searching, grep
searches for content within files, find
searches for file names themselves.
Defining some additional options in grep allows searching using colour where filenames and row positions are highlighted.
alias grepc='grep --color=auto -iRnH'
alias grepe='egrep --color=auto -iRnH'
The drawback is it cannot search for specific file extensions
grepc [PATTERN] *
works but
grepc [PATTERN] *.sh
does not work recursively
Using find
with pipe to xargs
to run grep
from above.
Search and syntax highlight the longest poly-A tail in a fastq file
cat [FILE] | perl -ne '$.%4 ==2 && print $_' | egrep --color=auto -iRnH "A{14,}" -
We want to replace the [PATTERN]
with text of interest, quoted patterns can contain metacharacters.
for all files of the form *.sh
find . -name "*.sh" -print | xargs -n1 -I{} grep --color=auto -iRnH [PATTERN] {} 2> /dev/null
This does allow files of certain extensions to be recursively searched for content.