script is printing output correct but not the actual output.
Basically what the script is doing it taking a 1 flat file
then it is splits the file into smaller files in 1000 record increments
then it creates another file and adds the header the file contents of the old file.
and the file with the header is then renamed to file format i want which is txt.
Now the problem is that the file never renames but when i print it it shows the new file name as the txt file i wanted. but it never changes the physical file.
Hope you guys could please help me the rest of the script works fine . the file splits file and the header and contents are fine. deleting the old files and renaming to txt is where i am having the problem. -
#!/usr/bin/perl
-
$| = 1;
-
-
use File::Copy;
-
-
######################### Splitting Files ################################
-
my $read = "Files read from dir";
-
my $split = "Files split in 1000 records each";
-
my $del = "Source file deleted";
-
my $move = "Source files moved to /home/tibco/tibco/Susan/split_finish";
-
-
open(LOG, ">>/home/baddabing/Susan/splitlog.log") || die (" error recording log: $!");
-
my $time_now = localtime;
-
-
my $srcdir = "/home/baddabing/Susan/dropoff";
-
my $dest = "/home/baddabing/Susan/split_finish";
-
-
for (;;) {
-
opendir(DIR, $srcdir) or die "Can't open $srcdir: $!";
-
@files = grep {!/^\.+$/} readdir(DIR);
-
close(DIR);
-
-
if (!@files) {
-
print "No files in dir.\n\n";
-
last;
-
}
-
-
print "Time: $time_now ----- $_[0]", "\n";
-
print LOG "Time: $time_now ----- $_[0]", "\n";
-
-
##### Reading Header from File #####
-
$file = "@files";
-
print "Source File is $file \n\n";
-
-
open(INFILE, "< $srcdir/$file") or die (" Could not open File $!");
-
$line1 = <INFILE>;
-
close (INFILE);
-
print " This is the header: $line1 \n";
-
-
#UNIX Split Command Running
-
system "split -l 500 $srcdir/int_sap* $srcdir/int_sap*";
-
print "Time: $time_now ----- $_[1]", "\n";
-
print LOG "Time: $time_now ----- $_[1]", "\n";
-
sleep 2;
-
-
system "rm /home/tibco/tibco/Susan/dropoff/*.txt";
-
print "Time: $time_now ----- $_[2]", "\n";
-
print LOG "Time: $time_now ----- $_[2]", "\n";
-
sleep 1;
-
-
system "mv /home/baddabing/Susan/dropoff/* /home/baddabing/Susan/split_finish";
-
print "Source files were moved to /home/baddabing/Susan/split_finish\n\n";
-
print LOG "Time: $time_now ----- $_[3]", "\n";
-
sleep 1;
-
-
######################### Rename Files ####################################
-
-
my $path2 = "/home/tibco/tibco/Susan/split_finish";
-
opendir(DIR, $path2) || die "can't opendir $path: $!";
-
@files2 = grep {!/^\.+$/} readdir(DIR);
-
close(DIR);
-
-
$i = 1;
-
foreach (@files2) {
-
@_ = split(/\./,$_);
-
-
my $name = "$_";
-
-
my $name3 = "$_[0]";
-
chomp($name);
-
print "This is the name $name \n\n";
-
-
open(INFILE2,"< $dest/$name") || die(" Could not open INFILE2 File!");
-
$header = <INFILE2>;
-
chomp($header);
-
print "This is the infile header: $header \n ";
-
-
my $name2 = "$name$i";
-
-
print "************* $name2 ********** \n\n\n";
-
-
if($header eq "$line1") {}
-
else {
-
open(OUTFILE2, "> $dest/$name2") || die ("Could not OUTFILE2 open file $!");
-
print OUTFILE2 "$line1";
-
print OUTFILE2 "$header";
-
while (<INFILE2>) {
-
print OUTFILE2 "$_";
-
}
-
close OUTFILE2;
-
}
-
-
close INFILE2;
-
unlink($name);
-
print "File $name Removed \n\n";
-
-
my $new_name = $name3.$i.'.txt';
-
-
system "rn $dest/$name2 $new_name";
-
print "$new_name renaming is completed \n\n";
-
sleep 2;
-
-
$i++;
-
close LOG;
-
}
-
print "\n\n ---------------- All files processed ------------------\n\n";
-
}
3 1626
@jonathan184
Try calling - rename("$dest/$name2", $new_name) or print "$!\n";
instead of - system "rn $dest/$name2 $new_name";
Greetz, Doc
Thanks that worked but if i wanted to put it in the same dir as the source.
the renaming part i mean i want it to rename in the same dir and output there.
Right now the rename works and it outputting to the folder level up.
Nevermind I got it but thanks for all your help I guess i overlooked the simple stuff :)
@jonathan184
Try calling - rename("$dest/$name2", $new_name) or print "$!\n";
instead of - system "rn $dest/$name2 $new_name";
Greetz, Doc
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Robert |
last post by:
Hello,
I am trying to get output formatted from a non-php script that I post
to.
Example:
<form method=POST action=www.myurl.com/ColdFusion.cfm>
bla bla bla
</form>
|
by: teachtiro |
last post by:
Hi,
'C' says \ is the escape character to be used when characters are
to be interpreted in an uncommon sense, e.g. \t usage in printf(),
but for printing % through printf(), i have read that %%...
|
by: Tinus |
last post by:
Hello all,
Because you have been so helpfull the last couple of times, I thought after
testing and wasting more than 20 pages (and google-ling for 3 days :-( ). I
would ask you again for your...
|
by: DazedAndConfused |
last post by:
I have a 8.5 x 11 landscape document with about 1/4 inch of space on the
left and right where there is no print.
The document displays perfect in print preview, but when I print it, about
1/2 inch...
|
by: sathyashrayan |
last post by:
Dear group,
Following is a exercise from a book called "Oreilly's
practical C programming". I just wanted to do a couple of C
programming exercise. I do have K and R book, but let me try
some...
|
by: Vincent |
last post by:
Dear all,
I have implemented a class to export the content of RichTextBox to
image in WYSISYG mode so that line breaks on the screen are the same as
exported.
C# Code:
public struct...
|
by: Neo Geshel |
last post by:
Greetings.
BACKGROUND:
My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are
delivered as application/xhtml+xml for all non-MS web clients, and as
text/xml for all MS web...
|
by: Frank Rizzo |
last post by:
I am trying to print huge images (much bigger than target paper). I try
and use e.PageSettings.HardMarginX and e.PageSettings.HardMarginY in the
PrintDocument's PrintPage event to try and...
|
by: mehdi |
last post by:
Hi,
Consider a printing scenario where I have to draw the entire page on a
827x1169 (.01 inch) size. Thereafter, the entire bitmap has to be
resized to fill a given Bounds rectangle (keeping the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |