472,805 Members | 1,043 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

copy few lines from one file to another file.

Hi friends
I am new to perl so please guide me.

I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only.

My requirement is to copy backup log for the specific day (yesterday) and write in other file.
That file will be mailed to admin for ready reference.

So here is some text from that log file

Expand|Select|Wrap|Line Numbers
  1. ======== Mon Oct 22 23:00:00 2007: BEGIN NNM Backup.
  2.      * Options:
  3.          Staging area =  F:\NNM_ovbackup/ovbackup
  4.          Operational =  0
  5.          Analytical =  0
  6.          ovresume timeout = default
  7.      * Starting operational checkpoint step. (Mon Oct 22 23:01:49 2007)
  8.        Running pre_pause phase.
  9.        Running ovpause.
  10.        ovpause succeeded.
  11.          Running script: nnm_checkpoint.ovpl.
  12. ovresume timeout =:       default 
  13.              Copy data in E:/HP OpenView/NNM/databases/openview
  14.              Copy data in E:/HP OpenView/NNM/databases/eventdb
  15.              Copy data in E:/HP OpenView/NNM/log
  16.              Copy data in E:/HP OpenView/NNM/conf
  17.              Copy data in E:/HP OpenView/NNM/registration
  18.              Copy data in E:/HP OpenView/NNM/fields
  19.              Copy data in E:/HP OpenView/NNM/symbols
  20.              Copy data in E:/HP OpenView/NNM/lrf
  21.              Copy data in E:/HP OpenView/NNM/www/htdocs
  22.              Copy data in E:/HP OpenView/NNM/www/images
  23.              Copy data in E:/HP OpenView/NNM/www/protected
  24.              Copy data in E:/HP OpenView/NNM/databases/nnmet
  25.              Copy SNMP Configuration Database. 
  26.        Running ovresume.
  27.        ovresume succeeded.
  28.        Running post_resume phase.
  29.      * Starting analytical checkpoint step. (Mon Oct 22 23:31:54 2007)
  30.          Running script: nnm_checkpoint.ovpl.
  31. ovresume timeout =:       default 
  32.           Starting backup of SNMP Collect data. 
  33.              Running ovpause -v snmpCollect 
  34.              ovpause succeeded. 
  35.                 Running ovresume.
  36.              ovresume succeeded. 
  37.           Backup of SNMP Collect data completed successfully. 
  38.           Starting backup of Data Warehouse data. 
  39.           Backup of NNM Data Warehouse completed successfully. 
  40.  
  41. ======== Mon Oct 22 23:32:18 2007: END NNM Backup.
  42.  
  43. ======== Tue Oct 23 23:00:00 2007: BEGIN NNM Backup.
  44.      * Options:
  45.          Staging area =  F:\NNM_ovbackup/ovbackup
  46.          Operational =  0
  47.          Analytical =  0
  48.          ovresume timeout = default
  49.      * Starting operational checkpoint step. (Tue Oct 23 23:01:10 2007)
  50.        Running pre_pause phase.
  51.        Running ovpause.
  52.        ovpause succeeded.
  53.          Running script: nnm_checkpoint.ovpl.
  54. ovresume timeout =:       default 
  55.              Copy data in E:/HP OpenView/NNM/databases/openview
  56.              Copy data in E:/HP OpenView/NNM/databases/eventdb
  57.              Copy data in E:/HP OpenView/NNM/log
  58.              Copy data in E:/HP OpenView/NNM/conf
  59.              Copy data in E:/HP OpenView/NNM/registration
  60.              Copy data in E:/HP OpenView/NNM/fields
  61.              Copy data in E:/HP OpenView/NNM/symbols
  62.              Copy data in E:/HP OpenView/NNM/lrf
  63.              Copy data in E:/HP OpenView/NNM/www/htdocs
  64.              Copy data in E:/HP OpenView/NNM/www/images
  65.              Copy data in E:/HP OpenView/NNM/www/protected
  66.              Copy data in E:/HP OpenView/NNM/databases/nnmet
  67.              Copy SNMP Configuration Database. 
  68.        Running ovresume.
  69.        ovresume succeeded.
  70.        Running post_resume phase.
  71.      * Starting analytical checkpoint step. (Tue Oct 23 23:30:40 2007)
  72.          Running script: nnm_checkpoint.ovpl.
  73. ovresume timeout =:       default 
  74.           Starting backup of SNMP Collect data. 
  75.              Running ovpause -v snmpCollect 
  76.              ovpause succeeded. 
  77.                 Running ovresume.
  78.              ovresume succeeded. 
  79.           Backup of SNMP Collect data completed successfully. 
  80.           Starting backup of Data Warehouse data. 
  81.           Backup of NNM Data Warehouse completed successfully. 
  82.  
  83. ======== Tue Oct 23 23:31:16 2007: END NNM Backup.
  84.  
so i want to copy from today's date say ' Tue Oct 23 23:00:00 2007: BEGIN NNM Backup." till end of a file."


Thanks in Advance
Mahesh
Oct 24 '07 #1
3 12700
numberwhun
3,504 Expert Mod 2GB
First, you didn't post a question, you just posted a synopsis of what you are doing. Being that this is a learning forum, and not a script writing service, you will need to do a lot of the legwork. Why not try some code to do what you want to do and if you get stuck, please post the code here (in proper code tags) and we will assist you in troubleshooting it.

Regards,

Jeff
Oct 24 '07 #2
Hi Friends

Here i have writeen the program and getting the output by using print.

But i want output in a txt file. So how to get output of array to txt file.

here is my program

Expand|Select|Wrap|Line Numbers
  1. use File::Copy;
  2.  
  3. $ovbackupfile = "ovbackup.log.";
  4.  
  5. $my_test_file = "copyovbackup.log.";
  6.  
  7. $my_output_file = "output.txt";
  8.  
  9. copy($ovbackupfile,$my_test_file) or die "file can not be copied.";
  10.  
  11. my $time =localtime;
  12.  
  13. my @splitdate = split(/ /,$time);
  14.  
  15. print "this is array  $splitdate[0] $splitdate[1] $splitdate[2] $splitdate[4] \n";
  16.  
  17. $date="$splitdate[0] $splitdate[1] $splitdate[2] 23:00:00 $splitdate[4]: BEGIN NNM Backup.\n";
  18.  
  19. print "Date =$date";
  20.  
  21. print "this is current time : $time \n";
  22.  
  23. open  myhandle, "G:/test/copyovbackup.log" or die "unable to open : $! \n";
  24.     while (<myhandle>) 
  25.             {
  26.  
  27.                 if ($_ =~ m/$date/) 
  28.                     {
  29.                     print 'match';
  30.                     print "read this is :$_\n";
  31.                     #@lines =  <myhandle>;
  32.                     print "@lines";
  33.                     copy(<myhandle>,$my_output_file) or die "output file can not be copied.";
  34.                     } 
  35.  
  36.             }
  37.         close myhandle ;
  38.  
  39.  
Oct 26 '07 #3
numberwhun
3,504 Expert Mod 2GB
Hi Friends

Here i have writeen the program and getting the output by using print.

But i want output in a txt file. So how to get output of array to txt file.

here is my program

Expand|Select|Wrap|Line Numbers
  1. use File::Copy;
  2.  
  3. $ovbackupfile = "ovbackup.log.";
  4.  
  5. $my_test_file = "copyovbackup.log.";
  6.  
  7. $my_output_file = "output.txt";
  8.  
  9. copy($ovbackupfile,$my_test_file) or die "file can not be copied.";
  10.  
  11. my $time =localtime;
  12.  
  13. my @splitdate = split(/ /,$time);
  14.  
  15. print "this is array  $splitdate[0] $splitdate[1] $splitdate[2] $splitdate[4] \n";
  16.  
  17. $date="$splitdate[0] $splitdate[1] $splitdate[2] 23:00:00 $splitdate[4]: BEGIN NNM Backup.\n";
  18.  
  19. print "Date =$date";
  20.  
  21. print "this is current time : $time \n";
  22.  
  23. open  myhandle, "G:/test/copyovbackup.log" or die "unable to open : $! \n";
  24.     while (<myhandle>) 
  25.             {
  26.  
  27.                 if ($_ =~ m/$date/) 
  28.                     {
  29.                     print 'match';
  30.                     print "read this is :$_\n";
  31.                     #@lines =  <myhandle>;
  32.                     print "@lines";
  33.                     copy(<myhandle>,$my_output_file) or die "output file can not be copied.";
  34.                     } 
  35.  
  36.             }
  37.         close myhandle ;
  38.  
  39.  
First, I had asked before that you use the proper code tags to post your code. Please know that that was a request, not a suggestion, as you entering them saves the moderators from cleaning up behind you.

As for your issue, I see you used the copy function from the File::Copy module. That function takes two options, a file1 and a file2. What you have specified is a filehandle for file1 and I don't think that will work as it is a pointer to the file. You will want to possibly create a variable that references the file with its full path. (I could be wrong, but that is my 7am, just rolled out of bed, first observation).

Regards,

Jeff
Oct 26 '07 #4

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

Similar topics

6
by: Russell E. Owen | last post by:
At one time, mixing for x in file and readline was dangerous. For example: for line in file: # read some lines from a file, then break nextline = readline() # bad would not do what a naive...
18
by: Vasilis Serghi | last post by:
Presently I define the number of lines to be expected in a file when defining the array size and the initialisation of this array. This works fine for now, but i'm sure that in the future this...
8
by: Jared Wiltshire | last post by:
Hi, I've written the following code to copy one files contents line by line into another file. However I'm a bit dubious about using the infinite loop to do this. ifstream infile("File1.txt");...
17
by: Eric_Dexter | last post by:
def simplecsdtoorc(filename): file = open(filename,"r") alllines = file.read_until("</CsInstruments>") pattern1 = re.compile("</") orcfilename = filename + "orc" for line in alllines: if not...
9
by: Justme | last post by:
Novice programmer needs help with using fgets to read and ignore the first two lines of a file. I've gone thru the previous posting regarding fgets, but none of them seems to help my situation. I...
3
by: td0g03 | last post by:
Hello, I am trying to write a code to copy a file which I can do as you can see below. void copy () { // Local Definitions int c; int closeStatus; FILE* spProverbs ; FILE*...
1
by: jojmacgregor | last post by:
Hey, im new to VB6 and i want to know how to get visual basic to read multiple lines of a .txt file and show them in an input box, im looking ot get at least 6 line at once in an input box...Coding...
9
by: jaxx | last post by:
Hey all. I am pretty new to this. But I was hopeing i can get some help from here. Have searched the but haven't found the right thing for me. I would need a program that will read a file, with a...
2
by: masha2011 | last post by:
Hello all, I am very new to programming and I have recently started using python. I am interested in creating a file to essentially compare data points. I am curious if it is possible to read...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.