listing files excluding files from control file

I have a directory named Project.I have a control file which contains valid list of files.I would like list the files from directory Project which contains files other than listed in the control file.

Sample control file:

TEST
SEND
SFFFILE
CONTL

The directory contains followign files:
TEST
SEND
SFFFILE
CONTL
Link
seq
test
param

When i run a script it has to create a file with the following files.

Link
seq
test
param

Please give me any suggestion how to do this .Control file contains more file and dir also contains more file.Please tell the efficient way to do this.

Thanks

cd /project/directory
ls | grep -vxf /path/to/control/file > /path/to/output/file

In the project directory I have the following files.

TEST_10
TeST_11
SEND_101

If i run that command it should not list these files also becuase they start with the value from the control file.

it should not return TEST* files also.

Trivially, take out the -x option which requires the whole line to match, and add an -i option to make matching ignore case. However, that does not anchor searches to beginning of line, so e.g. a file named bestest will match the pattern test. Maybe you could accept a change to the control file format, to support full regular expressions? Then the control file should contain

^test
^send
^sfffile
^contl

It's possible to come up with a different workaround if this is not acceptable. If your needs are very specific, perhaps a small awk script would be best.

ls | awk 'NR==FNR { pat[++n] = "^" tolower($0); next; }
{ for (p in pat) if (tolower($0) ~ pat[p]) next; print }' ctlfile -

(With this script, you should keep the original control file.)

the below script is not returning any thing

ls | awk 'NR==FNR { pat[++n] = "^"$0; next; } { for (p in pat) if ($0 ~ pat[p]) next; print }' controlfile

I have the follwoing entried in control file.

TestFile

I have the follwoing list of file in my directory.
TestFile.ksh
TestFile.dat
test.TestFile

I am using the following command
ls | grep -vf controlfile

this is not returning any thing becuase all the files matched tha patteren.But i am expecting it should return test.TestFile.

How can i acheive this.

Thanks

Your requirements are not clear; need to be precise about them or it all gets lost in translation...and please use code tags.
The entries in the control file should match only the name of the file but not the extension...correct??

Here is the situation.I have control file which contains the following values.
TEST
SEND
SFFFILE
CONTL

The directory contains followign files:
TEST
SEND
SFFFILE
CONTL
Link
seq
test
paramTEST

When i run a script it has to create a file with the following files.

Link
seq
test
paramTEST

Thanks

ls -1 | \
awk '{
    if (NR==FNR) {
        f[$1]
        f[FILENAME]
    } else
        if (!($1 in f))
            print $1 >> "outfile"
}' cntrlfile -
Tsunami control_files # ls
CONTL  Link  paramTEST  script.pl  SEND  seq  SFFFILE  test  TEST
Tsunami control_files # cat CONTL | perl script.pl 
seq
test
paramTEST
Link
Tsunami control_files # cat script.pl 
while (<>)
{
	chomp;
	$key{$_} = 1;
}

opendir(DIR, ".");
@dir = grep { !/^\./ && $0 ne $_ } readdir(DIR);
closedir DIR;

foreach (@dir)
{
	next if defined ($key{$_});
	print "$_\n";
}
Tsunami control_files # 

Thi following command is not returning any thing.
ls -1 | \
awk '{
if (NR==FNR) {
f[$1]
f[FILENAME]
} else
if (!($1 in f))
print $1 >> "outfile"
}' cntrlfile -
Thanks

It's supposed not to be printing anything. It stores the values in "outfile". And you must fill "cntlfile" first.

I filled control file and i ran this command it is not creating any outfile.

Thanks

You must be doing something wrong:

Tsunami control_files # cat cntrlfile 
TEST
SEND
SFFFILE
CONTL
Tsunami control_files # ls -1 | \
> awk '{
>     if (NR==FNR) {
>         f[$1]
>         f[FILENAME]
>     } else
>         if (!($1 in f))
>             print $1 >> "outfile"
> }' cntrlfile -
Tsunami control_files # cat outfile 
Link
paramTEST
script.pl
seq
test
Tsunami control_files # ls
cntrlfile  CONTL  Link  outfile  paramTEST  script.pl  SEND  seq  SFFFILE  test  TEST
Tsunami control_files # 

I did some thing wrong.now it is working.Thanks for your help.One more thing if i want to do pattern search by reading values from control file.

I want to list only the file name which will not start with the values in the control file.

I'll use shamrock's code (hope he doesn't mind).

ls -1|\
awk '{
    if (NR==FNR) {
        f[$1]
        f[FILENAME]
    } else
    {
        doprint = 1;
        for (x in f)
                if (substr($1, 0, length(x)) == substr(x, 0, length($1))) doprint = 0;
        if (doprint)
                print $1
    }
}' cntrlfile -

Another way is to modify your cntrlfile and put a ^ on the beginning of every entry like

^TEST
^SEND
^SFFFILE
^CONTL

and then replace

if (substr($1, 0, length(x)) == substr(x, 0, length($1))) doprint = 0;

with

if ($1 ~ x) doprint = 0;

That would allow you to do more pattern matching inside cntrlfile.