#!/bin/bash #grepstatus.sh #Usage: ./grepstatus.sh "" "" "pipe to commands" #Example: ./grepstatus.sh "a" /usr/share/dict/words "|sed 's/^[0-9]\+://g' |sort |uniq >/tmp/f.txt" # "-n" flag is already passed by default which means your output will have line numbers returned at the end to get rid of this # use sed "s/^[0-9]\+://g" #-cripy if [ $# -lt 2 ]; then printf "Usage: ./grepstatus.sh '' '' 'pipe to commands'\n" printf "Example: ./grepstatus.sh 'a' /usr/share/dict/words '|sed \"s/^[0-9]\+://g\" |sort |uniq >/tmp/f.txt'\n" printf "\t\t-n flag is already passed by default which means your output will have line numbers returned.\n" printf "\t\tTo get rid of this pipe sed \"s/^[0-9]\+://g\"\n" exit fi; PIPE_CMD="" if [ "$3" != "" ]; then PIPE_CMD=" $3"; fi; LINE_COUNT=`wc -l $2|awk '{print $1}'` CMD="grep -n $1 $2 $PIPE_CMD &" eval $CMD GREP_PID=`ps auxww|grep "$2"|grep -v "grep $2"|grep "0:0[0-9] grep" |grep -v -e 'grep 0:0'|awk '{print $2}'` CUR_LINE=0; P=`ps aux |awk '{print $2}' |grep $GREP_PID` while [ "$P" != "" ]; do CUR_LINE=`strace -s 40 -e trace=write -p $GREP_PID 2>&1|head -2|grep -oe "\n[0-9]*:" |sed "s/[n:]//g" |tail -1|tr "\n" ' '` if [ $CUR_LINE ]; then tput el printf "\rline: $CUR_LINE of: $LINE_COUNT" printf "| %s %% complete" `python -c "print $CUR_LINE*100/$LINE_COUNT.0"` P=`ps aux |awk '{print $2}' |grep $GREP_PID` fi; done; printf "\n"