help me do grep
Jonathan I. Kamens
jik at athena.mit.edu
Tue Feb 26 09:04:49 AEST 1991
You could do something like this:
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: $0 pattern filename"
exit 1
fi
AWK='BEGIN { doprint = 0
record = ""
}
/\/\/\// { if (doprint) { printf("%s", record) }
record = ""
doprint = 0
next
}
/'$1'/ { doprint = 1 }
{ record = record $0 "\n" }'
awk "$AWK" $2
If you only want to compare your pattern to a certain line of the entry, then
you can count entry lines as you go along and only set doprint to true if the
pattern matches *and* the current line number is the line of the entry against
which you want to compare.
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.shell
mailing list