View Single Post
Old 01-16-2006, 07:23 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
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
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote