Directory Search Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Directory Search Perl
# 1  
Old 05-13-2012
Directory Search Perl

Code:
@scriptfiles=glob('*.txt');
 
foreach $file (glob('*.txt'))
{ 
    open(my $fh, $file) or die("Unable to open '$file': $!");  
    while (my $line = <$fh>)
    {
        if ($line =~ m/(Apple|Orange|Guava)/i) 
        {
            $Sheet->Cells($row,$col-1)->{'Value'} = $file;

The above snippet will open each text file in the current folder and do a match for the words and if its matched the file name will be printed..

How to do the same for the files in the current directory

Last edited by Scrutinizer; 05-13-2012 at 06:48 AM..
# 2  
Old 05-22-2012
What is the difference between current folder and current directory?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to search for a directory with if clause?

Hello All, I want to do a conditional search for a directory, i.e pathname=/abc/def foldername=xyz if ( $pathname/$foldername/aaa ) then .................. fi Here i am searching for aaa directory inside the path and if it exist then it should go inside the loop. Can... (1 Reply)
Discussion started by: Pramod_009
1 Replies

2. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

3. Shell Programming and Scripting

Change to directory and search some file in that directory in single command

I am trying to do the following task : export ENV=aaa export ENV_PATH=$(cd /apps | ls | grep $ENV) However, it's not working. What's the way to change to directory and search some file in that directory in single command Please help. (2 Replies)
Discussion started by: saurau
2 Replies

4. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

5. Shell Programming and Scripting

How to search/replace a directory path in a file using perl

Hello All, Here is what I am trying to do and maybe you guys can point me in the right direction. I have a file that contains the following string(s): WARNING: </d1/test/program1> did not find item1 WARNING: </d1/test/program1> item1 does not exist WARNING: </d1/test/program2> item1 failed... (1 Reply)
Discussion started by: maxshop
1 Replies

6. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

7. Shell Programming and Scripting

How to search a directory in unix

Hi, I'm very new to shell script. Try to search a directory named construction using : find construction -type d. but don't know the path. so it can not stat. want to return the path of directory construction. can anyone help me. (4 Replies)
Discussion started by: samir_standing
4 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

9. Shell Programming and Scripting

search all files and sub directory

I wanted to search in all the sub directories under /vob/project (recurse) in everything inside /vob/project. search.run for x in `cat search.strings` do find /vob/project -type f -print | xargs grep -i $x > ~/$x.txt done search.string hello whoami I am getting the error ... (5 Replies)
Discussion started by: siva_jm
5 Replies

10. Programming

Directory tree search???

Hi all, I've got a problem, what function do i use to list the contents of all the directory tree (simular to "find")? Any other suggestions? Thank you all (3 Replies)
Discussion started by: solvman
3 Replies
Login or Register to Ask a Question