Something like this:
Code:
#!/bin/sh
if [ -z $1 ]; then
echo "Usage: $0 <file> <n>"
exit
fi
if [ -z $2 ]; then
echo "Usage: $0 <file> <n>"
exit
fi
if [ ! -f $1 ]; then
echo "File: $1 isn't a file"
exit
fi
for n in `grep -n $ $1 | awk -F ':' '{print $1}'`; do
LINE=`head -$n $1|tail -1`
# fetch the first n chars from line
CHARS=`echo $LINE | cut -c 0-$2`
# do whatever with CHARS
echo $CHARS
done
Remember you can form your echo statement any which way you want it to be displayed, and you can use awk/cut to pick anything out of your $LINE