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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help required the cut the whole contents from one file and paste it into new file
# 1  
Old 06-12-2012
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 :-

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 :-

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 :-

Code:
 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 :-

Code:
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 !

Last edited by methyl; 06-12-2012 at 09:05 AM.. Reason: Please use code tags for data and code samples ; changed formatting ( seemed to be editing at the same time )
# 2  
Old 06-12-2012
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?
# 3  
Old 06-12-2012
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)
# 4  
Old 06-12-2012
Quote:
Originally Posted by acidburn_007
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 [B]/home/usr/workarea/LogCopy.log

Code :-

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


Do you want to redirect the each set of contents in a new file?
Please elaborate your requirement with expected output provided.
# 5  
Old 06-13-2012
Problem Description

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 :-

Code:
(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:-

Code:
(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 :-
Code:
(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 :-
Code:
(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 :-

Code:
(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 :-
Code:
(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 :-
Code:
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 :-
Code:
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 :-
Code:
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 :-
Code:
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.

Last edited by Scott; 06-13-2012 at 04:34 AM.. Reason: Please use code tags and less formatting.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

2. Shell Programming and Scripting

How to cut a pipe delimited file and paste it with another file to form a comma separated outputfile

Hello ppl I have a requirement to split (cut in unix) a file (A.txt) which is a pipe delimited file into A1.txt and A2.txt Now I have to join (paste in unix) this A2.txt with external file A3.txt to form output file A4.txt which should be CSV (comma separated file) so that third party can... (25 Replies)
Discussion started by: etldev
25 Replies

3. Shell Programming and Scripting

Cut, replace and Paste a String from one file to another

I need to cut all the Strings in one file and Paste it in the another file in the Specific line by replacing the specific String. For Example Step 1: From the newfile.txt, i need to copy all the strings newfile.txt How are you, I am fine, How is your work newfle2.txt Hello david,... (2 Replies)
Discussion started by: Padmanabhan
2 Replies

4. Shell Programming and Scripting

Need to cut a some required data from file

Data_Consolidation_Engine_Part_2_Job2..TgtArBkt: ORA-00942: table or view does not exist I have some thing like above in the file.. Upto this portion Data_Consolidation_Engine_Part_2_Job2..TgtArBkt: the length can be vary .. Can some one help me in taking this portion alone ORA-00942:... (7 Replies)
Discussion started by: saj
7 Replies

5. Shell Programming and Scripting

Cut and paste data in new file

HI Guys, I have file A: Abc XyZ Abc Xyz Kal Kaloo Abc XyZ Abc Xyz Kalpooo Abc XyZ Abc Xyz Kloo Abc Abc Klooo I want file B Abc XyZ Abc Xyz Kal Kaloo Abc XyZ Abc Xyz Kalpooo Abc XyZ Abc Xyz Kloo File A is now 1 lines Abc Abc Klooo Cut all lines which have xyz... (2 Replies)
Discussion started by: asavaliya
2 Replies

6. Shell Programming and Scripting

Replace partial contents of file with contents read from other file

Hi, I am facing issue while reading data from a file in UNIX. my requirement is to compare two files and for the text pattern matching in the 1st file, replace the contents in second file by the contents of first file from start to the end and write the contents to thrid file. i am able to... (2 Replies)
Discussion started by: seeki
2 Replies

7. Shell Programming and Scripting

I want to delete the contents of a file which are matching with contents of other file

Hi, I want to delete the contents of a file which are matching with contents of other file in shell scripting. Ex. file1 sheel,sumit,1,2,3,4,5,6,7,8 sumit,rana,2,3,4,5,6,7,8,9 grade,pass,2,3,4,5,6,232,1,1 name,sur,33,1,4,12,3,5,6,8 sheel,pass,2,3,4,5,6,232,1,1 File2... (3 Replies)
Discussion started by: ranasheel2000
3 Replies

8. UNIX for Dummies Questions & Answers

Cut paste from one file to other

Hello, I am working on unix for the first time. I have to write a shell script where i want to cut paste from one file to other. File "1234.abc" is 03,12345555 16,936,x,x,120 16,936,x,x,100 49,12345555 03,12347710 16,936,x,x,115 16,936,x,x,122 49,12347710 03,12342222... (9 Replies)
Discussion started by: swapsb
9 Replies

9. UNIX for Dummies Questions & Answers

compare 2 file contents , if same delete 2nd file contents

Give shell script....which takes two file names as input and compares the contents, is both are same delete second file's contents..... I try with "diff"...... but confusion how to use "diff" with if ---else Thanking you (5 Replies)
Discussion started by: krishnampkkm
5 Replies

10. Shell Programming and Scripting

File contents required for emailing.

I have created three SQL scripts that are run by one central script. What I need to do is verify the output file from the three SQL scripts(KSH Scripts) is worth emailing. This I would like to do by verifiying the contents of the result file. The contrlooing script creates the result file... (6 Replies)
Discussion started by: jagannatha
6 Replies
Login or Register to Ask a Question