Error while appending records to a file

Hi,
I have a sample file which contains records.
Input File :
1 user1 username1\password@database-name
2 user2 username2\password@database-name
3 user3 username1\password@database-name
I should search for a 'username1\' in those records. If 'username1\' is found in those records, that record should be appended to a new file.
output file :
1 user1 username1\password@database-name
3 user3 username1\password@database-name
For the above requirement I have written a script as below.
#!/bin/ksh
set -x
cd directory
for file in `cat filename`
do
if [ -f *username1\* ]
then
$file >> outputfile
else
continue
fi
done
set +x
But when I execute the script it is not appeneding the records to output file. Please help me regarding this.
Thanks in advance.

 
grep username1 inputfile >>outputfile

Incase if you want to do the search with backslash.

grep username1\\\\ inputfile >>outputfile

Thanks for the answer.... it worked. But if we want to search for more than one user how we can proceed ?

grep username1 | username4 filename > outputfile

It is throwing an error that ksh:username4 not found. The situation is we dont know who ever will logn and what records I can get in that file. Please tell me how to find use the same command for different users ?

 grep -E 'username1|username4'  filename

thanks for ur answer.But when i typed the command:

grep -E 'username1|username4' inputfile>>outputfile

it gave an error that: illegal option -- E
Usage: grep -hblcnsviw pattern file . . .

Thanks in advance,

Hi, This should work for ksh.

 
#!/bin/ksh
grep -E 'username1|username4'  filename >output

What shell are you using?

try this--

grep -e 'username1' -e 'username4'  filename >output

I need to write a script that executes the already existing script continuously for 15 minutes.

i think that "while" loop is useful.

can anybody helps in this?

Thanks in advance