473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

problem in manupliating the file ???

Hi All,

Requirement :
1.read the content of the dir
2.seach for "prstat-Lvs" file
3.rename this file to *.txt (as this file doesn't have the file typeextension --raw file)
4.open this *.txt file & search for K&M
5.replace all K instance to *3 (manuplication)
6.replace all M instance to *4 (manuplication)
7.stored this calcuation in new file
8.rename this new file back to raw file
9.delete all the *.txt files

i have acheived this half a way (till step no 7) but the problem is, if i have more than 1 prstat-Lvs file, then code doesn't gives the correct raw files but instead it will give only 1 correct raw file & other one will be the replica of another.

Expand|Select|Wrap|Line Numbers
  1. my $dir = "C:\\Performance_svap\\INPUT_FILES\\*";
  2. my @file=glob("$dir");
  3. my $f;
  4. my $f2;
  5. my $oldfile;
  6. my @newfile;
  7. my @txtfile;
  8.         foreach $f (@file){
  9.             if ($f =~ /prstat-Lvs/){
  10.                 push (@prstat_Lvs,$f);    
  11.             foreach my $a (@prstat_Lvs){
  12.                 $oldfile = $a;
  13.                 my $newfile = $f . ".txt";
  14.                 rename($f,$newfile);
  15.                 push(@txtfile,$newfile);
  16.                 open (FH1,"$newfile") or die "Can't open $newfile : $!";
  17.                 $f2 = $a."new";
  18.                 $f2= $f2 . ".txt"; 
  19.                 open FH2, '>', $f2 or die "Couldn't open $f2: $!"; 
  20.                 while (<FH1>) { 
  21.                     @a_list=split(' ', $_);
  22.                     $new_line=" ";
  23.                     foreach $entry (@a_list) {
  24.                         if($entry =~ /K$/) {
  25.                             chop($entry);
  26.                             $entry=$entry*3;
  27.                         }
  28.                         if($entry =~ /M$/) {
  29.                             chop($entry);
  30.                             $entry=$entry*4;
  31.                     }
  32.                         $new_line=$new_line."    ".$entry;
  33.                 }
  34.                     print FH2 "$new_line\n";
  35.             }
  36.         }
  37.  
  38.                 close FH1;
  39.                 push(@newfile,$f2);
  40.                 close FH2;
  41.                 foreach my $k(@newfile){
  42.                     rename($k,$a);
  43.                 }
  44.                 foreach my $j(@txtfile){
  45.                     unlink $j;
  46.                 }
  47.                 }    
  48. }
  49.  
can i avoid step 7, instead just open the *.txt--do calculation--replace the value in the same file & rename it back to orginial raw file name ???

Thanks,
Vijayarl
Sep 30 '08 #1
1 1527
nithinpes
410 Expert 256MB
can i avoid step 7, instead just open the *.txt--do calculation--replace the value in the same file & rename it back to orginial raw file name ???

Thanks,
Vijayarl
If you are going to change the file back to it's raw format, you need not change the extension to .txt. You can straightaway open the file, modify and write result to a temp file and later rename the temp file back to original file.




i have acheived this half a way (till step no 7) but the problem is, if i have more than 1 prstat-Lvs file, then code doesn't gives the correct raw files but instead it will give only 1 correct raw file & other one will be the replica of another.
That is because of:
Expand|Select|Wrap|Line Numbers
  1. if ($f =~ /prstat-Lvs/){ 
  2.  
This line will take both 'prstat-Lvs' and 'prstat-Lvs.txt'. It should be:
Expand|Select|Wrap|Line Numbers
  1.  foreach $f (@file){ 
  2.             if (($f =~ /prstat-Lvs/)&&($f !~ /\.txt/)){ 
  3.                 push (@prstat_Lvs,$f);     
  4.             foreach my $a (@prstat_Lvs){ 
  5.                 $oldfile = $a; 
  6.                 my $newfile = $a . ".txt"; 
  7.  
Sep 30 '08 #2

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

Similar topics

7
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
6
by: trexim | last post by:
Hi, I am trying to create a Web Reference for CSTA using the URL http://www.ecma-international.org/standards/ecma-348/csta-wsdl/csta-wsdl-all-operations.wsdl Visual .Net complains that: "...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
8
by: Xela | last post by:
Hi A have a very annoying problem. I have written java strored procedures for DB2 v8.1. Their deployement and usage is fine as long as the server is a Windows one. But under Solaris 8 and Linux...
11
by: Marcus Jacobs | last post by:
Dear Group I have encountered a problem with fclose and I am wondering if anyone could provide some insight about this problem to me. Currently, I am working on a small personal project that is...
11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
15
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line,...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
4
by: Salad | last post by:
I have a situation where some, not all, users get the message "Couldn't find file "F:\AccessApps\AppName.mdw". This file is required for startup". My app the users are attempting to access is...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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...
0
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 project—planning, coding, testing,...

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.