#!/bin/sh # Print how many lines into a file a matching line is. Usage: # # $ wline NEEDLE HAYSTACK # 438/465 (94.19%) # $ # As for the 'k' command in 'dc'. PRECISION=2 NLINES=`wc -l "${2}" | cut -d " " -f 1` for LINE in `grep -n "${1}" "${2}" | cut -d ":" -f 1`; do echo -n "${LINE}"/"${NLINES} (" dc -e "${PRECISION} k ${LINE} 100 * ${NLINES} / n" echo "%)" done