Skip to content

Instantly share code, notes, and snippets.

@inodb
Created May 25, 2016 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inodb/693d4db1c52398734987e350d91d2c5d to your computer and use it in GitHub Desktop.
Save inodb/693d4db1c52398734987e350d91d2c5d to your computer and use it in GitHub Desktop.
Use grep --color=always to color a file by another file of patterns. Pretty useful for sequencing analysis
color_grep_file() {
COLOR_CMD="cat $1"
echo $COLOR_CMD
local i=31;
while read line; do
echo $line
COLOR_CMD="$COLOR_CMD | GREP_COLOR='01;$i' grep --color=always -E '$line|$'"
i=$(( $i + 1 ))
done < $2
COLOR_CMD="$COLOR_CMD | less -RS"
bash -c "$COLOR_CMD"
}
@inodb
Copy link
Author

inodb commented May 25, 2016

Example:

color_grep_file <(paste fastq/S04926HPool10.1.fastq fastq/S04926HPool10.2.fastq | awk 'NR % 4 == 2') <(cut -f2 barcodes.txt)

screen shot 2016-05-25 at 7 48 13 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment