@ OP
Your code of grep -i -A1 $1 /home/username/file.txt can work if the members with no special notes was replaced with a line space.
I did a test with your file entries. I enter your entries like so in a file:
Quote:
John Doe 111-111-1111
Mary Jane 222-222-2222
----> Manager
John Smith 333-333-3333
----> Director
|
Then ran:
Code:
grep -i -A1 "john" members
John Doe 111-111-1111
John Smith 333-333-3333
----> Director
As you can see, it prints all johns with special notes if applicable .
Another test with Mary
Code:
grep -i -A1 "mary" members
Mary Jane 222-222-2222
----> Manager
The key is to keep things in a uniform pattern. Use a line space for members with no special notes and the
grep -i -A1 should do ok.
BTW, awk and grep/egrep can have more flexibility of output results if you create a database of members using columns a special character as a field separator.
Quote:
John Doe|111-111-1111
Mary Jane|222-222-2222|Manager
John Smith|333-333-3333|Director
|
The pipe symbol is use here as the field separator.
- cheers