listing files excluding files from control file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users listing files excluding files from control file
# 1  
Old 08-15-2008
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
# 2  
Old 08-15-2008
Code:
cd /project/directory
ls | grep -vxf /path/to/control/file > /path/to/output/file

# 3  
Old 08-15-2008
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.
# 4  
Old 08-15-2008
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

Code:
^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.

Code:
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.)

Last edited by era; 08-15-2008 at 03:44 AM.. Reason: Oops, mixing Perl and awk syntax
# 5  
Old 08-15-2008
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
# 6  
Old 08-15-2008
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??
# 7  
Old 08-15-2008
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

2. Shell Programming and Scripting

Listing the file name and no of records in each files for the files created on a specific day

Hi, I want to display the file names and the record count for the files in the 2nd column for the files created today. i have written the below command which is listing the file names. but while piping the above command to the wc -l command its not working for me. ls -l... (5 Replies)
Discussion started by: Showdown
5 Replies

3. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

4. Shell Programming and Scripting

Copying files excluding some files

Hi, I have a folder which contains files in this format. abc-bin.000001 abc-bin.000002 abc-bin.000003 abc-bin.000004 abc-bin.000005 abc-bin.000006 abc-bin.000007 abc-bin.000008 abc-bin.000009 abc-bin.000010 abc-bin.index I want to copy all the files between abc-bin.000004... (6 Replies)
Discussion started by: arijitsaha
6 Replies

5. UNIX for Dummies Questions & Answers

Listing files without specific expression in the file

I am running Ubuntu 11.10 I have the following files. geo2503r05690585.html geo2503r06020612.html geo2503r06250641.html geo2503r06490658.html geo2503r06830686.html geo2503r05860601.html geo2503r06130624.html geo2503r06420648.html geo2503r06590682.html ... (4 Replies)
Discussion started by: kristinu
4 Replies

6. UNIX for Dummies Questions & Answers

need to zip all the files excluding todays file

HI All, At present in my server the log folder was filled up and causing memory issue. So I am planning to write a script in such a way that the files which are older than 30 days will be deleted and also need to find the files which were not compressed and need to compress this file.... (4 Replies)
Discussion started by: arumilli
4 Replies

7. UNIX for Dummies Questions & Answers

Count number of files in directory excluding existing files

Hi, Please let me know how to find out number of files in a directory excluding existing files..The existing file format will be unknown..each time.. Thanks (3 Replies)
Discussion started by: ammu
3 Replies

8. Shell Programming and Scripting

perl script for listing files and mailing the all files

Hi, I am new to perl: I need to write perl script to list all the files present in directory and mail should be come to my inbox with all the files present in that directory. advanced thanks for valuable inputs. Thanks Prakash GR (1 Reply)
Discussion started by: prakash.gr
1 Replies

9. Shell Programming and Scripting

search for files excluding binary files

Hi All, I need a solution on my following find command find ./.. -name '*.file' -print BTW This gives me the output as belows ./rtlsim/test/ADCONV0/infile/ad0_dagctst.file ./rtlsim/test/ADCONV0/user_command.file ./rtlsim/test/ADCONV0/simv.daidir/scsim.db.dir/scsim.db.file... (2 Replies)
Discussion started by: user_prady
2 Replies

10. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies
Login or Register to Ask a Question