Sponsored Content
Top Forums Shell Programming and Scripting Opening file and executing an action Post 302347701 by DemonixX on Wednesday 26th of August 2009 08:56:05 AM
Old 08-26-2009
Opening file and executing an action

I want the script to read the directory I am running the script from and print the contents of any file that has GX in it's title. This is the code needed[I think]. But how do I combine it?

Code:
#!/usr/bin/perl

opendir(CURRENT,".");
@list = readdir(CURRENT);
closedir(CURRENT);

foreach $item (@list){
  if($item =~ /GX/){
    print "$item\n";
  }
}

if(-e $filename){
 open(FILE,"$filename");
 while(<FILE>){ print };
 close(FILE);

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare 2 different file version and prompt for action

Hi, I need some assistance with comparing 2 diff application. The format of the first file is in TAR "filename.1.2.3.tar" . The second file is a running application for which i need to find the version and then prompt the user for action as below :- Once compared, It needs to prompt the user,... (0 Replies)
Discussion started by: systemali
0 Replies

2. Shell Programming and Scripting

Clean file in single action

What one finds challenging another finds simple... (HPUX B.11.11) I have a text file named something like 12345.dst that could look like this: DOG CAT NONE TEST CAT What I want to end up with is 12345.dst looking like this: CAT DOG TEST removing "NONE" should it be there and... (1 Reply)
Discussion started by: djp
1 Replies

3. Shell Programming and Scripting

Perform action file name written to the pipe

Hello, I have a script that monitors files uploaded via ftp. After a successful upload, the file name is written to the pipe. There is another program that reads this pipe and allows automatically run any program or script ( say test.sh ) to process the newly uploaded file. cat test.sh... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies

4. Shell Programming and Scripting

Take action if a particular file appears in a directory

This is my task - pls help Write a script that will run every 5 min and check if a particular file has appeared in a particular directory. Once it appears then rename the file and move it a bkp directory and run another script. (3 Replies)
Discussion started by: mrudula009
3 Replies

5. Shell Programming and Scripting

Take action only if a file is X hours (or seconds) old

shell: #!/bin/ash I searched and found a few relevant posts (here and here - both by porter, on the same day (?)) however both are just a do while loop, I need to check a file date and compare it to the current time. I would like it to say if file 'test' is more than 12 hours old than "right... (3 Replies)
Discussion started by: phdeez
3 Replies

6. Shell Programming and Scripting

shell script - search a file and perform some action

hi, i have a service on unix platform, it will generate traces in a particular folder i want to check using shell script if traces exist, then perform some action else continue to be in loop. filename is service.tra can you please help? thanks (4 Replies)
Discussion started by: gauravah
4 Replies

7. Shell Programming and Scripting

Opening Child Shell & Executing a script in the same context

Hi, Is the below possible (SHELL = tcsh)? -- I want to write an 'alias' something like this - alias set_my_work "setenv SOME_VAR;tcsh -i;source work_script.cshrc" The intention is to run this alias and enter a child shell, at the same time ensuring that the work_script.cshrc is source-ed.... (0 Replies)
Discussion started by: mishra.a.c
0 Replies

8. Shell Programming and Scripting

Xmllint - Xml-file problem --ods file not opening

Dear All, this is my first post on this Forum, glad to be here. I'm trying to fix an .ods file. Yes, I had a backup, but it's also corrupted. When opening the document I get this EM: read error format error discovered in the file in sub-document content.xml at 2,337040(row,col). So I... (3 Replies)
Discussion started by: jameslast
3 Replies

9. Shell Programming and Scripting

Opening a file in vi and automatically save and quit this file using shell script

Hi friends, In my shell script, I want to open a file using vi editor. After opening the file in vi, I want to save and quit this file automatically.... all through shell script. the code segment is: ------------------------------------------------------------ cd ~/netfpga/projects/scone/sw/... (2 Replies)
Discussion started by: sachinteotia
2 Replies

10. UNIX for Beginners Questions & Answers

Compare file name and take action

Have some files in /tmp/dir abc.zip 123.zip 345.zip and if name matches to 345.zip then take action My code.... am i doing something wrong ? Please advise. #!/bin/bash set -x cd /tmp/dir for i in *.* do if ] then (4 Replies)
Discussion started by: abhaydas
4 Replies
Perl::Critic::Policy::InputOutput::RequireCheckedSyscallUsermContributed Perl DocumePerl::Critic::Policy::InputOutput::RequireCheckedSyscalls(3pm)

NAME
Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls - Return value of flagged function ignored. AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
This performs identically to InputOutput::RequireCheckedOpen/Close except that this is configurable to apply to any function, whether core or user-defined. If your module uses Fatal, Fatal::Exception, or autodie then any functions wrapped by those modules will not trigger this policy. For example: use Fatal qw(open); open my $fh, $filename; # no violation close $fh; # yes violation use autodie; open $filehandle, $mode, $filename; # no violation Currently, autodie is not properly treated as a pragma; its lexical effects aren't taken into account. CONFIGURATION
This policy watches for a configurable list of function names. By default, it applies to "open", "print", "say" and "close". You can override this to set it to a different list of functions with the "functions" and "exclude_functions" settings. To do this, put entries in a .perlcriticrc file like this: [InputOutput::RequireCheckedSyscalls] functions = open opendir read readline readdir close closedir We have defined a few shortcuts for creating this list [InputOutput::RequireCheckedSyscalls] functions = :defaults opendir readdir closedir [InputOutput::RequireCheckedSyscalls] functions = :builtins [InputOutput::RequireCheckedSyscalls] functions = :all The ":builtins" shortcut above represents all of the builtin functions that have error conditions (about 65 of them, many of them rather obscure). You can require checking all builtins except "print" by combining the "functions" and "exclude_functions": [InputOutput::RequireCheckedSyscalls] functions = :builtins exclude_functions = print This is a lot easier to read than the alternative. The ":all" is the insane case: you must check the return value of EVERY function call, even "return" and "exit". Yes, this "feature" is overkill and is wasting CPU cycles on your computer by just existing. Nyah nyah. I shouldn't code after midnight. CREDITS
Initial development of this policy was supported by a grant from the Perl Foundation. This policy module is based heavily on policies written by Andrew Moore <amoore@mooresystems.com>. AUTHOR
Chris Dolan <cdolan@cpan.org> COPYRIGHT
Copyright (c) 2007-2011 Chris Dolan. Many rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-07 Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls(3pm)

Featured Tech Videos

All times are GMT -4. The time now is 02:53 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy