|
0
|
1 #!/bin/sh
|
|
|
2
|
|
|
3 ##
|
|
|
4 ## Galaxy wrapper for GREP command.
|
|
|
5 ##
|
|
|
6
|
|
|
7 # The only truly portable way of getting a fully resolved path of a file.
|
|
|
8 SCRIPT=$(perl -MCwd -e '$f=Cwd::realpath($ARGV[0]); die unless -e $f; print $f' "$0") || exit 1
|
|
|
9 SCRIPT_DIR=$(dirname "$SCRIPT")
|
|
|
10 ANSI_SCRIPT="$SCRIPT_DIR/ansi2html.sh"
|
|
|
11 [ -e "$ANSI_SCRIPT" ] || { echo "Error: utility script ($ANSI_SCRIPT) not found." >&2 ; exit 1 ; }
|
|
|
12
|
|
|
13 ##
|
|
|
14 ## command line arguments:
|
|
|
15 ## input_file
|
|
|
16 ## output_file
|
|
|
17 ## regex
|
|
|
18 ## COLOR or NOCOLOR
|
|
|
19 ## [other parameters passed on to grep]
|
|
|
20
|
|
|
21 INPUT="$1"
|
|
|
22 OUTPUT="$2"
|
|
|
23 REGEX="$3"
|
|
|
24 COLOR="$4"
|
|
|
25
|
|
|
26 shift 4
|
|
|
27
|
|
|
28 if [ -z "$COLOR" ]; then
|
|
|
29 echo "usage: $0 INPUTFILE OUTPUTFILE REGEX COLOR|NOCOLOR [other grep patameters]" >&2
|
|
|
30 exit 1
|
|
|
31 fi
|
|
|
32
|
|
|
33 if [ ! -r "$INPUT" ]; then
|
|
|
34 echo "error: input file ($INPUT) not found!" >&2
|
|
|
35 exit 1
|
|
|
36 fi
|
|
|
37
|
|
|
38 # Messages printed to STDOUT will be displayed in the "INFO" field in the galaxy dataset.
|
|
|
39 # This way the user can tell what was the command
|
|
|
40 echo "grep" "$@" "$REGEX"
|
|
|
41
|
|
|
42 if [ "$COLOR" = "COLOR" ]; then
|
|
|
43 GREP_COLOR='1;34' grep --color=always -P "$@" -- "$REGEX" "$INPUT" |
|
|
|
44 sh "$ANSI_SCRIPT" > "$OUTPUT" || exit 1
|
|
|
45
|
|
|
46 elif [ "$COLOR" = "NOCOLOR" ]; then
|
|
|
47 grep -P "$@" -- "$REGEX" "$INPUT" | grep -v "^--$" > "$OUTPUT" || exit 1
|
|
|
48 else
|
|
|
49 echo Error: third parameter must be "COLOR" or "NOCOLOR" >&2
|
|
|
50 exit 1
|
|
|
51 fi
|