Sponsored Content
Top Forums Shell Programming and Scripting Searching the file of below pattern through perl script from different location Post 302731489 by anuragpgtgerman on Thursday 15th of November 2012 06:57:57 AM
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";
 }

 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
File::chdir(3pm)					User Contributed Perl Documentation					  File::chdir(3pm)

NAME
File::chdir - a more sensible way to change directories VERSION
version 0.1006 SYNOPSIS
use File::chdir; $CWD = "/foo/bar"; # now in /foo/bar { local $CWD = "/moo/baz"; # now in /moo/baz ... } # still in /foo/bar! DESCRIPTION
Perl's "chdir()" has the unfortunate problem of being very, very, very global. If any part of your program calls "chdir()" or if any library you use calls "chdir()", it changes the current working directory for the whole program. This sucks. File::chdir gives you an alternative, $CWD and @CWD. These two variables combine all the power of "chdir()", File::Spec and Cwd. $CWD Use the $CWD variable instead of "chdir()" and Cwd. use File::chdir; $CWD = $dir; # just like chdir($dir)! print $CWD; # prints the current working directory It can be localized, and it does the right thing. $CWD = "/foo"; # it's /foo out here. { local $CWD = "/bar"; # /bar in here } # still /foo out here! $CWD always returns the absolute path in the native form for the operating system. $CWD and normal "chdir()" work together just fine. @CWD @CWD represents the current working directory as an array, each directory in the path is an element of the array. This can often make the directory easier to manipulate, and you don't have to fumble with "File::Spec->splitpath" and "File::Spec->catdir" to make portable code. # Similar to chdir("/usr/local/src/perl") @CWD = qw(usr local src perl); pop, push, shift, unshift and splice all work. pop and push are probably the most useful. pop @CWD; # same as chdir(File::Spec->updir) push @CWD, 'some_dir' # same as chdir('some_dir') @CWD and $CWD both work fine together. NOTE Due to a perl bug you can't localize @CWD. See "BUGS and" for a work around. EXAMPLES
(We omit the "use File::chdir" from these examples for terseness) Here's $CWD instead of "chdir()": $CWD = 'foo'; # chdir('foo') and now instead of Cwd. print $CWD; # use Cwd; print Cwd::abs_path you can even do zsh style "cd foo bar" $CWD = '/usr/local/foo'; $CWD =~ s/usr/var/; if you want to localize that, make sure you get the parens right { (local $CWD) =~ s/usr/var/; ... } It's most useful for writing polite subroutines which don't leave the program in some strange directory: sub foo { local $CWD = 'some/other/dir'; ...do your work... } which is much simpler than the equivalent: sub foo { use Cwd; my $orig_dir = Cwd::abs_path; chdir('some/other/dir'); ...do your work... chdir($orig_dir); } @CWD comes in handy when you want to start moving up and down the directory hierarchy in a cross-platform manner without having to use File::Spec. pop @CWD; # chdir(File::Spec->updir); push @CWD, 'some', 'dir' # chdir(File::Spec->catdir(qw(some dir))); You can easily change your parent directory: # chdir from /some/dir/bar/moo to /some/dir/foo/moo $CWD[-2] = 'foo'; CAVEATS
Assigning to @CWD calls "chdir()" for each element @CWD = qw/a b c d/; Internally, Perl clears @CWD and assigns each element in turn. Thus, this code above will do this: chdir 'a'; chdir 'a/b'; chdir 'a/b/c'; chdir 'a/b/c/d'; Generally, avoid assigning to @CWD and just use push and pop instead. "local @CWD" does not work. "local @CWD>" will not localize @CWD. This is a bug in Perl, you can't localize tied arrays. As a work around localizing $CWD will effectively localize @CWD. { local $CWD; pop @CWD; ... } Volumes not handled There is currently no way to change the current volume via File::chdir. NOTES
$CWD returns the current directory using native path separators, i.e. on Win32. This ensures that $CWD will compare correctly with directories created using File::Spec. For example: my $working_dir = File::Spec->catdir( $CWD, "foo" ); $CWD = $working_dir; doing_stuff_might_chdir(); is( $CWD, $working_dir, "back to original working_dir?" ); Deleting the last item of @CWD will act like a pop. Deleting from the middle will throw an exception. delete @CWD[-1]; # OK delete @CWD[-2]; # Dies What should %CWD do? Something with volumes? # chdir to C:Program FilesSierraHalf Life ? $CWD{C} = '\Program Files\Sierra\Half Life'; DIAGNOSTICS
If an error is encountered when changing $CWD or @CWD, one of the following exceptions will be thrown: o Can't delete except at the end of @CWD o Failed to change directory to '$dir' HISTORY
Michael wanted "local chdir" to work. p5p didn't. But it wasn't over! Was it over when the Germans bombed Pearl Harbor? Hell, no! Abigail and/or Bryan Warnock suggested the $CWD thing (Michael forgets which). They were right. The "chdir()" override was eliminated in 0.04. David became co-maintainer with 0.06_01 to fix some chronic Win32 path bugs. As of 0.08, if changing $CWD or @CWD fails to change the directory, an error will be thrown. SEE ALSO
File::pushd, File::Spec, Cwd, "chdir" in perlfunc, "Animal House" <http://www.imdb.com/title/tt0077975/quotes> SUPPORT
Bugs / Feature Requests Please report any bugs or feature requests by email to "bug-file-chdir at rt.cpan.org", or through the web interface at <http://rt.cpan.org/Public/Dist/Display.html?Name=File-chdir>. You will be automatically notified of any progress on the request by the system. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. <https://github.com/dagolden/file-chdir> git clone https://github.com/dagolden/file-chdir.git AUTHORS
o David A Golden <dagolden@cpan.org> o Michael G Schwern <schwern@pobox.com> (original author) COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Michael G Schwern and David A Golden. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.10.1 2011-11-02 File::chdir(3pm)
All times are GMT -4. The time now is 01:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy