Mercurial > repos > xuebing > sharplabtool
comparison tools/unix_tools/grep_wrapper_old.sh @ 0:9071e359b9a3
Uploaded
| author | xuebing |
|---|---|
| date | Fri, 09 Mar 2012 19:37:19 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9071e359b9a3 |
|---|---|
| 1 #!/bin/sh | |
| 2 | |
| 3 ## | |
| 4 ## Galaxy wrapper for GREP command. | |
| 5 ## | |
| 6 | |
| 7 ## | |
| 8 ## command line arguments: | |
| 9 ## input_file | |
| 10 ## output_file | |
| 11 ## regex | |
| 12 ## COLOR or NOCOLOR | |
| 13 ## [other parameters passed on to grep] | |
| 14 | |
| 15 INPUT="$1" | |
| 16 OUTPUT="$2" | |
| 17 REGEX="$3" | |
| 18 COLOR="$4" | |
| 19 | |
| 20 shift 4 | |
| 21 | |
| 22 if [ -z "$COLOR" ]; then | |
| 23 echo usage: $0 INPUTFILE OUTPUTFILE REGEX COLOR\|NOCOLOR [other grep patameters] >&2 | |
| 24 exit 1 | |
| 25 fi | |
| 26 | |
| 27 if [ ! -r "$INPUT" ]; then | |
| 28 echo "error: input file ($INPUT) not found!" >&2 | |
| 29 exit 1 | |
| 30 fi | |
| 31 | |
| 32 # Messages printed to STDOUT will be displayed in the "INFO" field in the galaxy dataset. | |
| 33 # This way the user can tell what was the command | |
| 34 echo "grep" "$@" "$REGEX" | |
| 35 | |
| 36 if [ "$COLOR" == "COLOR" ]; then | |
| 37 # | |
| 38 # What the heck is going on here??? | |
| 39 # 1. "GREP_COLORS" is an environment variable, telling GREP which ANSI colors to use. | |
| 40 # 2. "--colors=always" tells grep to actually use colors (according to the GREP_COLORS variable) | |
| 41 # 3. first sed command translates the ANSI color to a <FONT> tag with blue color (and a <B> tag, too) | |
| 42 # 4. second sed command translates the no-color ANSI command to a </FONT> tag (and a </B> tag, too) | |
| 43 # 5. htmlize_pre scripts takes a text input and wraps it in <HTML><BODY><PRE> tags, making it a fixed-font HTML file. | |
| 44 | |
| 45 GREP_COLORS="ms=31" grep --color=always -P "$@" -- "$REGEX" "$INPUT" | \ | |
| 46 grep -v "^\[36m\[K--\[m\[K$" | \ | |
| 47 sed -r 's/\[[0123456789;]+m\[K?/<font color="blue"><b>/g' | \ | |
| 48 sed -r 's/\[m\[K?/<\/b><\/font>/g' | \ | |
| 49 htmlize_pre.sh > "$OUTPUT" | |
| 50 | |
| 51 | |
| 52 if (( $? )); then exit; fi | |
| 53 | |
| 54 elif [ "$COLOR" == "NOCOLOR" ]; then | |
| 55 grep -P "$@" -- "$REGEX" "$INPUT" | grep -v "^--$" > "$OUTPUT" | |
| 56 if (( $? )); then exit; fi | |
| 57 else | |
| 58 echo Error: third parameter must be "COLOR" or "NOCOLOR" >&2 | |
| 59 exit 1 | |
| 60 fi | |
| 61 | |
| 62 exit 0 |
