hi all,
from a shell (ksh) script, i am doing a 'grep'. how do i find out the number of lines returned from that 'grep' command ??
thanks in advance.
hi all,
from a shell (ksh) script, i am doing a 'grep'. how do i find out the number of lines returned from that 'grep' command ??
thanks in advance.
use grep -c option
thanks for the reply. grep -c only Prints only a count of the lines that contain the pattern. i wanted the actual line and also the number of lines returned as well.
is there a way to check the length of a string in unix ?? i could possibly use this to see how many lines were returned.
Use AWK (nawk or /usr/xpg4/bin/awk on Solaris):
awk 'END{print c}/pattern/&&++c' input
line=$(grep -n "$pattern" "$filename" | cut -f1 -d':')
found=$(echo $line | awk '{print NF}'