I am trying to rewrite the grep command to capture the record(line) that has a pattern match and then to print out the matching line plus the 5 lines above and below the matched line so one can view the match in context. My problem is capturing the matched record. Here is a sample of what I have been trying. All HELP will be greatly appreciated.
#!/bin/bash
while getopts in OPTION
do
case "$OPTION" in
i) u_l_case=true ;;
n) number=true ;;
*) other=true ;;
esac
done
while [ $# -gt 0 ]
do
if echo $1 | grep -v '^-' > /dev/null 2>&1; then
if [ ! -a $1 ]; then
pattern=$1
echo "$pattern"
else
echo $1
fi
fi
shift
done
awk 'BEGIN {RS = "\n"}
{for (i=1; i<=NR; i++) {
record=$0
if (match(record, pattern)) {
printf ("%s", record)}
}
}' $1 $pattern
#!/bin/bash
while getopts in OPTION
do
case "$OPTION" in
i) u_l_case=true ;;
n) number=true ;;
*) other=true ;;
esac
done
while [ $# -gt 0 ]
do
if echo $1 | grep -v '^-' > /dev/null 2>&1; then
if [ ! -a $1 ]; then
pattern=$1
echo "$pattern"
else
echo $1
fi
fi
shift
done
awk 'BEGIN {RS = "\n"}
{for (i=1; i<=NR; i++) {
record=$0
if (match(record, pattern)) {
printf ("%s", record)}
}
}' $1 $pattern