a snippet of your data file too would help. Along with more than just your function code would help more, but,
I think i have a ruff idea what you're trying to do. you are asking for input from the cli, then using that name to try and find a match to it in a different file?
two loops. outside loop is you control loop, the inner loop takes the name and holds it checking against every thing in the file? sub strings, or splitting the line up into separate words depending on the situation, as you're employing egrep and sed to try and do your dirty work for you.
Code:
#!/bin/bash
read -p "Give me user name, Yo " UName
max=$(cat testusers | wc -l)
echo "max $max"
while [[ $count -lt $max ]] ;
do
{
while read L;
do
{
if [[ "$L" == "$UName" ]] ; then
{
echo "$UName : $L MATCH"
}
fi
((count++))
} done
} done <testusers
test file was just something simple.
Code:
Bob
bob
boB
BoB
BOB
bOb
using two separate files
Code:
#!/bin/bash
while read F ;
do
{
while read L;
do
{
if [[ "$L" == "$F" ]] ; then
echo "$L : $F MATCH"
fi
((count++))
} done <testfile
} done <testusers
two files
Code:
# file 1
bob
sally 90
Jill::70
carera 22
#file 2
Bob 34
bob 99
sally 99
Jill::70
boB
sally 88
BoB
sally 90
carera
BOB
sally 12
bOb
results
Code:
$ ./findUser
Jill::70 : Jill::70 MATCH
sally 90 : sally 90 MATCH