Searching the file of below pattern through perl script from different location


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching the file of below pattern through perl script from different location
# 1  
Old 11-15-2012
Searching the file of below pattern through perl script from different location

Hi All,

I am creating a small per script but I am getting the error "Unable to open file because No such file or directory".My code is below.I am trying to go into the below location so using chdir and then seraching the log files of below pattern.

Code:
#!/usr/bin/perl -w
 chdir '/projects/stp/stpbuild/logs/BuildLogs/';
 $a = `ls -ltr | grep STP-201211`;
 open (TEMP, "$a") || die "Unable to open file $a because $!\n";
 @files = (<$TEMP>);
 foreach $file (@files) {
   print $file . "\n";
 }

# 2  
Old 11-15-2012
Hi anuragpgtgerman,

What is the result of
Code:
print "(($a))\n";

just before the open instruction?
# 3  
Old 11-15-2012
And if I got you right, instead of using external commands (ls and grep), you could write a terse version using directory handles and the grep built-in operator:
Code:
#!/usr/bin/perl -w
opendir my $dh, '/projects/stp/stpbuild/logs/BuildLogs/' or die "Could not opendir: $!\n";
for my $file (grep /STP-201211/, readdir $dh) {
 print "File : $file\n";
}

# 4  
Old 11-15-2012
its working now
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Searching and printing the only pattern using awk,sed or perl

Hi All, i have an output of command vmstat as below : $ vmstat System configuration: lcpu=4 mem=5376MB ent=1.00 kthr memory page faults cpu ----- ----------- ------------------------ ------------ ----------------------- r b avm fre re pi... (10 Replies)
Discussion started by: omkar.jadhav
10 Replies

2. Shell Programming and Scripting

Searching for a pattern in a file...

The problem is similar to my yesterday post I Would like an awk script that does the following: I have a file (f1) that contains 1 2 3 4 5and another one (f2) that contains 8|a 9|b 0|c 1|d 2|e 3|f 4|g 5|h 6|i 7|jAnd I'd like to get this: 1|d 2|e 3|f 4|g (5 Replies)
Discussion started by: tukuyomi
5 Replies

3. UNIX for Dummies Questions & Answers

Searching the date pattern in a file

Hi, I would like to search the pattern based on the date like "2010/08/15". I tried using / in the file giving /<<pattern>>. when i tried this it turns to /2010/+8, but not going to the pattern what ever i want. This is how the data in the file. INFO | jvm 1 | 2010/05/26 13:30:33... (5 Replies)
Discussion started by: venkatesht
5 Replies

4. Shell Programming and Scripting

Searching a pattern in a file.

Hi Guys, I am writing a shell script to extract only the error message from a log file. I am having difficulty in searching the highlighted text in the below code. <runtimeinfo datetime="Sun Apr 04 20:02:52 EDT 2008" docid="" source="RAWDATA" event="ERROR"... (2 Replies)
Discussion started by: prash1986
2 Replies

5. Shell Programming and Scripting

Script for searching a pattern in 5 files and deleting the patterns given

Hi All, I have written the below script that searches for the pattern in a file and delete them if present. please can some one have a look and suggest the changes in the script. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read... (4 Replies)
Discussion started by: Shazin
4 Replies

6. Shell Programming and Scripting

Searching a pattern in file and deleting th ewhole line containing the pattern

Hi All, Please can someone assist in the script I have made that searches a pattern in a file and delete the whole line containing the pattern. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read value # check if the user has... (1 Reply)
Discussion started by: Shazin
1 Replies

7. Shell Programming and Scripting

Searching words in a file containing a pattern

Hi all, I would like to print words in a file seperated by whitespaces containing a specific pattern like "=" e.g. I have a file1 containing strings like %cat file1 The= some= in wish= born <eof> .I want to display only those words containing = i.e The= , some=,wish= ... (5 Replies)
Discussion started by: sree_123
5 Replies

8. 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

9. Shell Programming and Scripting

Find a pattern in a file at a particular location

Hi all, I have a question on how to search for a pattern in a file and return a value if it is present at that particular location. How to read each line and each character for the pattern in the file of any format. Eg for the file format: attached the file (1 Reply)
Discussion started by: sparks
1 Replies

10. Shell Programming and Scripting

searching pattern in another file and print

Suppose u have a file 12 22 73 another file L22D SSS S12J LLL H77K PPP J25O LOP I73S lOP K99O PLO so output shud like S12J LLL L22D SSS I73S lOP Thanks (2 Replies)
Discussion started by: cdfd123
2 Replies
Login or Register to Ask a Question