Searching list of entries in file for actual files in dir


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Searching list of entries in file for actual files in dir
# 1  
Old 10-18-2006
Searching list of entries in file for actual files in dir

Hi all,

I have a file entries.txt that contains a number of entries all on seperate lines e.g.

test1
test2
test3
test4

Then in a directory called /TestFiles I have a number of files that could contain the above text in the file name

e.g. qwertytest1.csv qwertytest2.csv qwertytest3.csv

How can I search the entries.txt to see if if the entries exist in the TestFiles directory?

Thanks,
# 2  
Old 10-18-2006
Code:
while read entry; do
  for f in /TestFiles/*$entry*; do
    print "Found $f"
  done
done < entries.txt

# 3  
Old 10-18-2006
Code:
ls /TestFiles/* | grep -f entries.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files in dir and grep accordingly

bash or c-shell On Solaris 10 I need a command that will list the files of a directory, and grep each of those filenames out of a static text file, and then only echo field 2 of the static text file. Something like this: #> ls -1 /home/dir/ | each filename grep $filename static.txt |awk... (4 Replies)
Discussion started by: ajp7701
4 Replies

2. Shell Programming and Scripting

List no. of files in a directory/sub dir's and also an consolidated report as required

Need help on below query asap. Thanks. The below is the directory structure: /home/suren under /suren the following are the directories /bin /log /error /bin contains the following files abc.txt bcd.ksh cde.sh wer.ksh ghi (file with out any extension) /log contains the following... (1 Reply)
Discussion started by: sureng
1 Replies

3. Shell Programming and Scripting

Copy files to a dir using from a list

Hi all, I'd very grateful for some help with the following: I have a directory with several subdirectories with files in them. All files are named different, even between different subdirectories. I also have a list with some of those file names in a txt file (without the path, just the file... (5 Replies)
Discussion started by: foracoffee
5 Replies

4. Shell Programming and Scripting

how to list all the files for today in the dir

I am trying following ... ls -ltrh | grep 'Dec 2' but it is displaying files for last year also ..as this dir is full of files from last 3-5 yrs I only want to files for today. e.g . ls -ltrh | grep 'Dec 2' -rw-r----- 1 ajay ajay 0 Dec 2 2010 text23.txt -rw-r----- ... (19 Replies)
Discussion started by: ajaypatil_am
19 Replies

5. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

6. Shell Programming and Scripting

Searching String from set of similar File pattern from the Dir

Guys, Here is the script that searches string from the set of similar files from the log directory, All the file patterns are defined as input file, from where the script should map to those files in the LOG_DIR and should start searching the strings from all those similar files. ... (1 Reply)
Discussion started by: raghunsi
1 Replies

7. Shell Programming and Scripting

How to get a list of files in a dir w/o sub-directories?

Hi I am looking for the correct syntax to find all files in the current directory without listing sub-directoris. I was using the following command, but it still returns subdirectoris and files inside them: $ ls -laR | grep -v ^./ Any idea? Thanks PS I am in ksh88 (4 Replies)
Discussion started by: aoussenko
4 Replies

8. Shell Programming and Scripting

Generate a change list of files/dir

Is there a tool that can diff a directory and generate a change list of files in that directory based on a previous snapshot on the directory? For example /etc/a.txt:changed /etc/b.txt:removed /etc/c.txt:added Thanks! (1 Reply)
Discussion started by: overmindxp
1 Replies

9. Shell Programming and Scripting

Searching for array in large list of files

I tried to make the title/subject detailed, but well.. have to keep it short as well. I am wanting to take a large list of strings, and search through a large list of files to hopefully find numerous matches. I am not sure the quickest way to do this though. // List of files file1.txt... (2 Replies)
Discussion started by: Rhije
2 Replies

10. Shell Programming and Scripting

How to copy specified files from list of files from dir A to dir B

Hello, fjalkdsjfkldsajflkajdskl (3 Replies)
Discussion started by: pmeesara
3 Replies
Login or Register to Ask a Question