Thursday, August 20, 2015

Grep with function name (with different colors) recursively

#!/bin/csh

#

# Maximum can be any parameters (if user has given '*' as files)
#
if ( $#argv < 1 ) then
    echo "\n[USAGE]: $0 <pattern> <files>\n";
    exit
endif

#awk -v re=$1 '/^[[:alpha:]]/{f=FNR"-"$0} $0~re{printf "%s\n%d:%s\n--\n",f,FNR,$0; f="" }' $2
#awk -v re='CANMIC_MX_LOCK' '/^[[:alpha:]]/{f=FNR"-"$0} $0~re{printf "\033[1;31m%s\n\033[34m%d:\033[0m%s\n--\n",f,FNR,$0; f="" "\033[0m" }' *
#awk -v re=$1 '/^[[:alpha:]]/{f=FNR"-"$0} $0~re{printf "\033[1;31m%s\n\033[34m%d:\033[0m%s\n--\n",f,FNR,$0; f="" "\033[0m" }' $2
    foreach i (`find . -name "*" -type f -print`)
    awk -v re=$1 '/^[[:alpha:]]/{f=FNR"-"$0} $0~re{printf "\033[1;32m[%15s]\t\033[1;31m%-64s\t\033[34m%s\n--\033[0m\n",FILENAME,f,$0; f="" }' $i
    end

Output:
[./canmic/canmic_err.c] 53-canmic_state_set(int newstate, int *oldstate)                                CANMIC_MX_LOCK();
--
[./canmic/canmic_err.c] 77-canmic_stateful_write(char *blkdata, size_t blksize, int blknmbr)            CANMIC_MX_LOCK();
--
[./canmic/canmic_err.c] 93-canmic_stateful_dirty(scnMsg_t *scnmsg)                                      CANMIC_MX_LOCK();
--
[./canmic/canmic_err1.h]                                                                                #define CANMIC_MX_LOCK()        do {    \
--
[./canmic/canmic_err.h]                                                                         #define CANMIC_MX_LOCK()        do {    \

No comments:

Post a Comment