473,763 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

script is printing output correct but not the actual output

154 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. $| = 1;
  3.  
  4. use File::Copy;
  5.  
  6. ######################### Splitting Files ################################
  7. my $read = "Files read from dir";
  8. my $split = "Files split in 1000 records each";
  9. my $del = "Source file deleted";
  10. my $move = "Source files moved to /home/tibco/tibco/Susan/split_finish";
  11.  
  12. open(LOG, ">>/home/baddabing/Susan/splitlog.log") || die (" error recording log: $!");
  13. my $time_now = localtime;
  14.  
  15. my $srcdir = "/home/baddabing/Susan/dropoff";
  16. my $dest = "/home/baddabing/Susan/split_finish";
  17.  
  18. for (;;) {
  19.     opendir(DIR, $srcdir) or die "Can't open $srcdir: $!";
  20.     @files = grep {!/^\.+$/} readdir(DIR);
  21.     close(DIR);
  22.  
  23.     if (!@files) {
  24.         print "No files in dir.\n\n";
  25.         last;
  26.     }
  27.  
  28.     print "Time: $time_now ----- $_[0]", "\n";
  29.     print LOG "Time: $time_now ----- $_[0]", "\n";
  30.  
  31.     ##### Reading Header from File #####
  32.     $file = "@files";
  33.     print "Source File is $file \n\n";
  34.  
  35.     open(INFILE, "< $srcdir/$file") or die (" Could not open File $!");
  36.     $line1 = <INFILE>;
  37.     close (INFILE);
  38.     print " This is the header: $line1 \n";
  39.  
  40.     #UNIX Split Command Running
  41.     system "split -l 500 $srcdir/int_sap* $srcdir/int_sap*";
  42.     print "Time: $time_now ----- $_[1]", "\n";
  43.     print LOG "Time: $time_now ----- $_[1]", "\n";
  44.     sleep 2;
  45.  
  46.     system "rm /home/tibco/tibco/Susan/dropoff/*.txt";
  47.     print "Time: $time_now ----- $_[2]", "\n";
  48.     print LOG "Time: $time_now ----- $_[2]", "\n";
  49.     sleep 1;
  50.  
  51.     system "mv /home/baddabing/Susan/dropoff/* /home/baddabing/Susan/split_finish";
  52.     print "Source files were moved to /home/baddabing/Susan/split_finish\n\n";
  53.     print LOG "Time: $time_now ----- $_[3]", "\n";
  54.     sleep 1;
  55.  
  56. ######################### Rename Files ####################################
  57.  
  58.     my $path2 = "/home/tibco/tibco/Susan/split_finish";
  59.     opendir(DIR, $path2) || die "can't opendir $path: $!";
  60.     @files2 = grep {!/^\.+$/} readdir(DIR);
  61.     close(DIR);
  62.  
  63.     $i = 1;
  64.     foreach (@files2) {
  65.         @_ = split(/\./,$_);
  66.  
  67.         my $name = "$_";
  68.  
  69.         my $name3 = "$_[0]";
  70.         chomp($name);
  71.         print "This is the name $name \n\n";
  72.  
  73.         open(INFILE2,"< $dest/$name") || die(" Could not open INFILE2 File!");
  74.         $header = <INFILE2>;
  75.         chomp($header);
  76.         print "This is the infile header: $header \n ";
  77.  
  78.         my $name2 = "$name$i";
  79.  
  80.         print "************* $name2 ********** \n\n\n";
  81.  
  82.         if($header eq "$line1") {}
  83.         else {
  84.             open(OUTFILE2, "> $dest/$name2") || die ("Could not OUTFILE2 open file $!");
  85.             print OUTFILE2 "$line1";
  86.             print OUTFILE2 "$header";
  87.             while (<INFILE2>) {
  88.                 print OUTFILE2 "$_";
  89.             }
  90.             close OUTFILE2;
  91.         }
  92.  
  93.         close INFILE2;
  94.         unlink($name);
  95.         print "File $name Removed \n\n";
  96.  
  97.         my $new_name = $name3.$i.'.txt';
  98.  
  99.         system "rn $dest/$name2 $new_name";
  100.         print "$new_name renaming is completed \n\n";
  101.         sleep 2;
  102.  
  103.         $i++;
  104.         close LOG;
  105.     }
  106.     print "\n\n ---------------- All files processed ------------------\n\n";
  107. }
Feb 21 '07 #1
3 1648
docsnyder
88 New Member
@jonathan184

Try calling
Expand|Select|Wrap|Line Numbers
  1. rename("$dest/$name2", $new_name) or print "$!\n";
instead of
Expand|Select|Wrap|Line Numbers
  1. system "rn $dest/$name2 $new_name";
Greetz, Doc
Feb 22 '07 #2
jonathan184
154 New Member
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.
Feb 22 '07 #3
jonathan184
154 New Member
Nevermind I got it but thanks for all your help I guess i overlooked the simple stuff :)

@jonathan184

Try calling
Expand|Select|Wrap|Line Numbers
  1. rename("$dest/$name2", $new_name) or print "$!\n";
instead of
Expand|Select|Wrap|Line Numbers
  1. system "rn $dest/$name2 $new_name";
Greetz, Doc
Feb 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3791
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>
7
96320
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 %% should be used. Wouldn't it have been better (from design perspective) if the same escape character had been used in this case too. Forgive me for posting without verfying things with any standard compiler, i don't have the means for now.
8
9629
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 help. The problem is this: If I print a rectangle which begins at (0,0) and the margins are also set to 0 (l:0, t:0, r:0, b:0) then it prints fine (ok, not quite because 0,0 is inside the none printable area but I corrected for that by checking...
7
2485
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 on the right is not printed (leaving about 3/4 inch empty margin on the right side of the page). The left side starts about 1/4 inch in and prints just like I expect it to. I tried setting the margins to 0 and OriginAtMargins = True. The print...
6
9423
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 simple one. Exercise 4-2: Write a program to print a block E using asterisks (*), where the E has a height of seven characters
0
11158
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 STRUCT_RECT
8
5912
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 clients (Internet Explorer). My flash content was originally brought in via the “flash satay” method, but I have since used some server-side magic do deliver one <objecttag
8
9018
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 determine the maximum area that I can print on. However, the edge of the image invariably gets cut off, as if the HardMargin info is wrong. I posted the code below as I can't understand what I am doing wrong. Is information in e.PageSettings reliable?...
1
2116
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 aspect ratio fixed). To do so, I've just wrote the following code in the PrintPage event: Graphics g = e.Graphics; Rectangle bounds = TheDestinationRectangle; Rectangle rc = new Rectangle(0, 0, (Int32)(827 * g.DpiX / 100), (Int32)
0
9386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10145
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9822
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.