I have a process run weekly where I must convert data formats for about thirty files. I read a text file that provides all of the filenames and switch settings.
My perl code is:
Every once in a while, one of the files is empty, & this is ok.
But the perl program aborts at that open line. Right now, when this happens, I simply remove the file info from the text file listing, and restart. But, I must remember to put the line(s) back in for the next week.
QUESTION:
is it better to do a "next" when the file open fails, or
do some kind of File::stat command to know if the file exists first
In shell scripting, one can do an "if [ -e filename ] " kind of thing
In shell scripting, one can do an "if [ -e filename ] " kind of thing
you can if (-f "/etc/passwd") { warn "file exists" } in perl too, most of the modern test flags exist.
the big problem i have is when the file is after the mundane open(FH,..) that your doing. and the print FH "" fails. This take a little bit of care and feeding but its worth it imo.
The following command to replace text in place in multiple files in a directory is tripping up on filename spaces (Windows environment). I really don't know Perl.
find '\\server\directory' | xargs perl -pi -e 's/textA/textB/g'Mike (2 Replies)
Hello,
I'm attempting to write a tool that checks an IP address for existing PTR records then if there are no PTR records does a ping to see if it response.
Then if there is no response, it should print a message saying
This is what I have so far.
#!/usr/bin/perl
$nxdomain =... (4 Replies)
Korn Shell
I have hundreds of small files like below created every day. A midnight cron job moves them to the location /u04/temp/logs
But sometimes I have to manually move these files based a certain dates or time.
I have two basic requirements
1.Using mv command I want to move all .dat... (2 Replies)
I write this bit of code to calculate the mean and variance for all the files in one directory and print the mean and variance in a separate folder but with the same file name.
FILES="data/*"
for X in $FILES
do
name=$(basename $X)
awk '{x=$0; s+=$0; n++}
END{mean=s/n; for (i in x){ss... (20 Replies)
Hello, I am working on a coding project for a class and to test the program I have created, I have come up with 100 different test cases. The program takes four text files as input, so each of the test cases is contained in a folder with four files.
I have a folder called 'tests', within which... (1 Reply)
Hi, I just wondering I done program which will list .jpg extension file but if there is not .jpg file in current directory display error how to do it ; here is my code
#!/bin/sh
echo "Enter a program function :" # declear User input
read func1 func2
## user must input list follow by... (1 Reply)
Hello,
I want to run one (not multiple) action if an element doesn't exist in array.
for example:
@array = (1..10);
foreach $el (@array)
{
if ($el != 11)
{
print "number not found\n";
}
}
the output of this simple script:
number not found (3 Replies)
Hello, I'm a computer science major and I'm having problems dealing with file names with spaces in them. Particularly I'm saving a file name in a variable and then using the variable in a compare function i.e.
a='te xt.txt'
b='file2.txt'
cmp $a $b
If anyone could help me with this particular... (10 Replies)
Hi ,
My requirement is that i need to search for a number of strings in a log file and print them with line numbers.The search should be date wise.
The sample log file is :
Jan 17 02:45:34 srim6165 MQSIv500: (UKBRKR1P_B.LZ_
BENCHMARKS)BIP2648E: Message backed out to a queue; node... (6 Replies)