The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find excluding the hidden files arunkumar_mca UNIX for Advanced & Expert Users 3 01-27-2008 11:45 PM
search for files excluding binary files user_prady Shell Programming and Scripting 2 09-05-2007 12:18 AM
Excluding files using tar cXzf sampipe UNIX for Dummies Questions & Answers 11 07-28-2005 09:46 AM
Recursive directory listing without listing files psingh UNIX for Dummies Questions & Answers 4 05-10-2002 10:52 AM
Excluding Old Files on AWK !!! alexalvarenga Shell Programming and Scripting 2 01-16-2002 10:25 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-15-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
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 (permalink)  
Old 08-15-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Code:
cd /project/directory
ls | grep -vxf /path/to/control/file > /path/to/output/file
  #3 (permalink)  
Old 08-15-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
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 (permalink)  
Old 08-15-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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 02:44 AM.. Reason: Oops, mixing Perl and awk syntax
  #5 (permalink)  
Old 08-15-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
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 (permalink)  
Old 08-15-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
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 (permalink)  
Old 08-15-2008
ukatru ukatru is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 38
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0