searching folder in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting searching folder in perl
# 1  
Old 07-25-2007
searching folder in perl

i will tell my problem with example:
if i have a folder name called sree1.7.3
i know the starting name say sree and also path say /usr/lib.
so i want the folder name.
and how can i link this folder in makefile
thank u
sree
# 2  
Old 07-25-2007
This will help you in finding all matching directories as per your criteria:
Code:
#!/usr/bin/perl
use strict;
use warnings;
my $path = "/usr/lib";
my $name = "sree";

opendir (DIR_TO_SEARCH, $path)  or  die "Failed to open directory $path : $!";
my @dirs_found = grep { /$name/ } readdir DIR_TO_SEARCH;
closedir (DIR_TO_SEARCH);

for my $dir (@dirs_found) {
        print $dir , "\n";
}

# 3  
Old 07-26-2007
thank u for u help,
it's sloved my problem.
can i ask u one more question.
if i want to search 1.txt.
if found this files in two diffrent path suppose
/usr/lib/1.txt
/usr/local/share/1.txt
i need only single path so how can stop the search.
and also need only /usr/lib not /usr/lib/1.txt
thank u very much
sree
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Searching for file types by count in specific folder in RHEL 6

So I'm trying to search for the top 10 or 15 items under a directory by file type. I want to run a command on a directory and get something like the following: Example of expected output.. .PDF: 100, .txt: 95, .word: 80.. What would be the best way of going about this? I've searched around... (2 Replies)
Discussion started by: shackle101
2 Replies

2. UNIX for Dummies Questions & Answers

Grep in Perl - Searching through multiple files

I'm attempting to use grep in Perl with very little success. What I would like to do in Perl is get the output of the following grep code: grep -l 'pattern' * This gives me a list of all the files in a directory that contain the pattern that was searched. My attempts to do this in Perl... (4 Replies)
Discussion started by: WongSifu
4 Replies

3. Shell Programming and Scripting

Searching a string in a file using perl

Hi I would like to read a file using perl and search for a string (last entry). Then read that into an array and do further grep File content for ex: comp=a,value=30,runtime=12,type=lic comp=d,value=15,runtime=2,type=lic comp=a,value=90,runtime=43,type=lic... (1 Reply)
Discussion started by: vivek_damodaran
1 Replies

4. Shell Programming and Scripting

searching multiple patterns in perl

Hi, I have code like: Output it is comming as: Rels: WM2 Rels: WG2 Rels: 5 - pre/prods.pl Rels: 6 Rels: 7 Rels: 8 Rels: 10 Rels: Int But i want only "Rels: 5" pattern Just above "- pre/prods.pl". By... (7 Replies)
Discussion started by: Anjan1
7 Replies

5. Shell Programming and Scripting

Perl searching special words in lines

Hi , i am a new with perl, i want to made a script that find in file rows that start with specil words, as an example a line will start with" ............................................. specialword aaa=2 bbb=5 ............................................. and to put this in a new file... (3 Replies)
Discussion started by: alinalin
3 Replies

6. UNIX for Dummies Questions & Answers

Perl searching and printing multiple target in the same line

Hello, I'm trying to create a program in perl called myfind.pl; To use the program: (at the command line)$ program.pl keyword filename note: the keyword is any word or regular expression and it should display the result just like when you 'cat' the file name but with the keyword in... (2 Replies)
Discussion started by: Horizon666
2 Replies

7. Shell Programming and Scripting

Perl help - Searching for a pattern and return the position

Hi, I need to search a file, in each line I need to check for occurance of '1' from a particular position through the next 32 bytes. If 1 is found, i need to return the position. Here is an example of the file and the output i need. Please help. I'm new to perl and unix. File: ... (1 Reply)
Discussion started by: gpaulose
1 Replies

8. Shell Programming and Scripting

Searching array of arrays in perl

Suppose there are two arrays of arrays: @A = ( , , , ); @B = ( , , , , ); For each of $A, $A, $A..., I want to find the corresponding one in @B (match the letter, like $A eq $B), and print out both the second item, for example, $A and $B. How can I do this in perl? grep + map? Hope I... (1 Reply)
Discussion started by: zx1106
1 Replies

9. Shell Programming and Scripting

Perl: searching for a string in a file...

Hi All, I need to search for a string in a file that I've opened and base a decision on the result. The logic is this: "if the word 'Shared' appears on the first line then do this on the whole file else do this on the whole file " The code I currently have isn't working:... (4 Replies)
Discussion started by: pondlife
4 Replies

10. Shell Programming and Scripting

searching a file from folder

suppose in my unix login 10 folders is present. i have a abc.h header file. i forget where this header file is present. so which command i will use in unix, so that it will search from all folders. (3 Replies)
Discussion started by: debasis.mishra
3 Replies
Login or Register to Ask a Question