Help required the cut the whole contents from one file and paste it into new file

Hi,

First of all sincere apologies if I have posted in a wrong section ! Please correct me if I am wrong !

I am very new to UNIX scripting.

Currently my problem is that I have a code file at the location /home/usr/workarea/GeneratedLogs.log :-

Code :-

(Feb 7, 571 7:07:29 AM), Setup
(Feb 7, 571 7:07:29 AM), Setup
(Feb 7, 571 7:07:29 AM), Setup
(Feb 7, 571 7:07:29 AM), Setup
(Feb 7, 571 7:07:29 AM), Setup
(Feb 8, 003 11:23:03 PM), Setup
(Feb 8, 003 11:23:03 PM), Setup
(Feb 8, 003 11:23:03 PM), Setup
(Feb 8, 003 11:23:03 PM), Setup
(Feb 9, 861 11:39:11 PM), Setup
(Feb 9, 861 11:39:11 PM), Setup
(Feb 9, 861 11:39:11 PM), Setup

Now I want to cut the contents from this file based on date i.e. I am expecting the below code in a new file at the location /home/usr/workarea/LogCopy.log

Code :-

(Feb 7, 571 7:07:29 AM), Setup
(Feb 7, 571 7:07:29 AM), Setup
(Feb 7, 571 7:07:29 AM), Setup
(Feb 7, 571 7:07:29 AM), Setup
(Feb 7, 571 7:07:29 AM), Setup

I tried with the following script :-

 find /home/usr/workarea/GeneratedLogs.log -mtime +0 -exec cp {} /home/usr/workarea/LogCopy.log \;

But this script just created a new file and copied the contents from the parent file to the new created file and deleted the parent file !

I even tried the cut command also :-

find /home/usr/workarea/GeneratedLogs.log -mtime +0 -exec cut -d: -f1,100 /home/usr/workarea/LogCopy.log \;

But this command is not working and I am not sure what is wrong with it !!!!

My requirement is to cut the contents from the parent file and paste it into a new file which will be created during runtime and the new created should also carry the timestamp !

Could anyone mind to help me in this regard !

Thanks in advance !

You have different set of similar rows. You want to put them all in separate-separate files based on time stamp or only the first set of rows in another file?

This problem is best solved with a script (if you are looking for simplicity). However, please give further details about:

  1. What is the integer value after the date field and before the timestamp? It does not look like the year field to me.
  2. As the above OP asked, how do you want your o/p. In separate files as per the dates, or is it just a specific date you want picked up. In case it is a specific date, can it be hard coded in the solution or will it be dependent on system date (i.e. system date -1, -2 and so on)

Do you want to redirect the each set of contents in a new file?
Please elaborate your requirement with expected output provided.

Hi,

Thanks to you all for showing interest in helping me out !

Well. I will again try to define the problem and the resolution I have reached so far !

Currently I have a log file at the location /home/usr/workarea/GeneratedLogs.log in which the logs get appended every second :-

Logs example :-

(Apr 15, 2011 12:22:00 PM), Setup, com.installshield.product.service.registry.PureJavaRegistryServiceImpl, dbg.registry
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
last modified date = (Wed Apr 13 11:05:22 CEST 2011) -----

(Apr 16, 2011 1:47:39 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
ast modified date = (Wed Apr 20 13:49:11 CEST 2011) -----
(Apr 16, 2011 1:49:15 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug

(Apr 16, 2011 3:14:25 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 17, 2011 7:40:10 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 17, 2011 7:40:10 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 22, 2011 6:28:15 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 22, 2011 6:29:15 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 22, 2011 6:29:15 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 22, 2011 6:19:15 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."

Now I want to cut the contents from this file based on date i.e. I am expecting the below log files in a new file at the location /home/usr/workarea/LogCopy.log

Expected Log File e.g LogCopy.log_11_04_15_12_22:-

(Apr 15, 2011 12:22:00 PM), Setup, com.installshield.product.service.registry.PureJavaRegistryServiceImpl, dbg.registry
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
(Apr 15, 2011 12:22:02 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug

LogCopy.log_11_04_16_1_47 :-

(Apr 16, 2011 1:47:39 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug
ast modified date = (Wed Apr 20 13:49:11 CEST 2011) -----
(Apr 16, 2011 1:49:15 PM), Setup, com.tibco.installer.util.TIBCOInstaller, dbg.Debug

(Apr 16, 2011 3:14:25 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"

LogCopy.log_11_04_17_7_40 :-

(Apr 17, 2011 7:40:10 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 17, 2011 7:40:10 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"

LogCopy.log_11_04_21_11_13 :-

(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 21, 2011 11:13:33 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."

LogCopy.log_11_04_22_6_28 :-

(Apr 22, 2011 6:28:15 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 22, 2011 6:29:15 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."
(Apr 22, 2011 6:29:15 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, target platform: name="AIX" version="5.3" arch="ppc"
(Apr 22, 2011 6:19:15 PM), Setup, com.installshield.wizardx.conditions.PlatformWizardBeanCondition, dbg.platform, condition platform: name="Windows .*" version="." arch
="."

Problem faced :-

I used the following command :-

find /home/usr/workarea/GeneratedLogs.log -mtime +0 -exec cp{} /home/usr/workarea/LogCopy.log_$(date +%y_%m_%d_%H_%M) \;

This command was able to copy the contents from the parent log file into the new child file. But, the contents in the parent file were not deleted !

So, I tried with the following cut command :-

find /home/usr/workarea/GeneratedLogs.log -exec cut -c- /home/usr/workarea/LogCopy.log_$(date +%y_%m_%d_%H_%M) \;

This command failed to perform its operation !! No idea why !!!!!!! LLL

So, I tried the other way round.

(1.) I used the following command to first copy the contents from parent file to the new child file using :-

find /home/usr/workarea/GeneratedLogs.log -mtime +0 -exec cp{} /home/usr/workarea/LogCopy.log_$(date +%y_%m_%d_%H_%M) \;

(2.) Later I used the following command to empty the parent file at the location : /home/usr/workarea/GeneratedLogs.log

By using :-

cat /dev/null > GeneratedLogs.log

Requirement :-

Is it not possible to club all this in one single command ! i.e. from the parent log file all the logs should get cut paste into new child file appended with the date.

Once the new child files are created then I need to delete those files which are older than 7 days ! Now how will I achieve that ????

I hope now I have made problem clear. Please let me know if more inputs are required in arriving at a solution !

Thanks.