Help For File modification


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help For File modification
# 1  
Help For File modification

Hi,
I have a file. File contains are as follows :
Code:
Feb 19, 2012 5:05:00 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Feb 19, 2012 5:05:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 771 ms
Feb 20, 2012 5:05:00 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 20, 2012 5:05:00 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
Feb 20, 2012 5:05:00 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor test.xml
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /opt/apache-tomcat-6.0.29/webapps/SpendAnalyzer does not exist
        at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:142)
        at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4249)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4418)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
..............................................................................
...............................................................................
..............................................................................
..............................................................................
............................................................................
............................................................................
.............................................................................
Feb 24, 2012 5:05:01 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Feb 24, 2012 5:05:01 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.XmlWebApplicationContext@5e4be2cc: display name 
Feb 24, 2012 5:05:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
Feb 24, 2012 5:05:02 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context

I want to cut only Feb 20 data or Feb 21 or any date.Here I have cut Feb 20 data. I want to pass date as a variable because I want to cut any date data.
The output like this
Code:
Feb 20, 2012 5:05:00 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Feb 20, 2012 5:05:00 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
Feb 20, 2012 5:05:00 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor test.xml
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /opt/apache-tomcat-6.0.29/webapps/SpendAnalyzer does not exist
        at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:142)
        at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4249)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4418)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)

Please help me.
Thanks in advance

Last edited by Scott; 02-24-2012 at 02:33 PM.. Reason: Replaced QUOTE tags with CODE tags
# 2  
Code:
$ awk -v date="Feb 19" '{if($0~date){print;getline;print}}' o.txt
Feb 19, 2012 5:05:00 PM org.apache.coyote.http11.Http11Protocol init
 INFO: Initializing Coyote HTTP/1.1 on http-8080
 Feb 19, 2012 5:05:00 PM org.apache.catalina.startup.Catalina load
 INFO: Initialization processed in 771 ms

$ awk -v date="Feb 20" '{if($0~date){print;getline;print}}' o.txt
 Feb 20, 2012 5:05:00 PM org.apache.catalina.core.StandardService start
 INFO: Starting service Catalina
 Feb 20, 2012 5:05:00 PM org.apache.catalina.core.StandardEngine start
 INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
 Feb 20, 2012 5:05:00 PM org.apache.catalina.startup.HostConfig deployDescriptor
 INFO: Deploying configuration descriptor test.xml

$ awk -v date="Feb 24" '{if($0~date){print;getline;print}}' o.txt
 Feb 24, 2012 5:05:01 PM org.springframework.web.context.ContextLoader initWebApplicationContext
 INFO: Root WebApplicationContext: initialization started
 Feb 24, 2012 5:05:01 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
 INFO: Refreshing org.springframework.web.context.support.XmlWebApplicationContext@5e4be2cc: display name 
 Feb 24, 2012 5:05:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
 INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
 Feb 24, 2012 5:05:02 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
 INFO: Bean factory for application context

# 3  
Quote:
Originally Posted by itkamaraj
Code:
$ awk -v date="Feb 19" '{if($0~date){print;getline;print}}' o.txt
Feb 19, 2012 5:05:00 PM org.apache.coyote.http11.Http11Protocol init
 INFO: Initializing Coyote HTTP/1.1 on http-8080
 Feb 19, 2012 5:05:00 PM org.apache.catalina.startup.Catalina load
 INFO: Initialization processed in 771 ms

$ awk -v date="Feb 20" '{if($0~date){print;getline;print}}' o.txt
 Feb 20, 2012 5:05:00 PM org.apache.catalina.core.StandardService start
 INFO: Starting service Catalina
 Feb 20, 2012 5:05:00 PM org.apache.catalina.core.StandardEngine start
 INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
 Feb 20, 2012 5:05:00 PM org.apache.catalina.startup.HostConfig deployDescriptor
 INFO: Deploying configuration descriptor test.xml

$ awk -v date="Feb 24" '{if($0~date){print;getline;print}}' o.txt
 Feb 24, 2012 5:05:01 PM org.springframework.web.context.ContextLoader initWebApplicationContext
 INFO: Root WebApplicationContext: initialization started
 Feb 24, 2012 5:05:01 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
 INFO: Refreshing org.springframework.web.context.support.XmlWebApplicationContext@5e4be2cc: display name 
 Feb 24, 2012 5:05:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
 INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
 Feb 24, 2012 5:05:02 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
 INFO: Bean factory for application context

Hi itkamaraj,
Your code only print two line after search the date. If I want to print next 10 line after searching the date then what will do?
# 4  
it prints 2 lines because it runs getline once... to print 10 lines run getline 9 times...

I'd simplify that too:

Code:
awk -v CTX=10 -v date="Feb 24" '$0 ~ date { print; for(N=0; N<(CTX-1); N++) { if(getline>0) print } }' o.txt

Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #551
Difficulty: Medium
If variable i has the value 10, after x = 5 + (i++); the value of x after this code is 15.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do you get the last modification date of a file?

I'm trying to get the date output to be in the form yyyy-mm-dd (e.g. 2013-01-18) !/bin/sh modDate=$(stat -c %y $1) echo $modDate >> $1 When I run this on another file (by typing ./dateScript theFile.txt), I keep getting this message: stat: illegal option -- c What's wrong with my code... (2 Replies)
Discussion started by: Nate18
2 Replies

2. Programming

File content modification

HI All, I have a file with content as below Filename: my name is xyz my name abc my name is bdf end Filename: my name uvx my name edd my name jhn end i want to edit the content and save into another file as Filename1: my name is xyz Filename1: my name abc Filename1: my name is... (4 Replies)
Discussion started by: jhon1257
4 Replies

3. Shell Programming and Scripting

File Modification

Hi, I have a file input.txt. cat input.txt output is as follows : Code: "0001"~"name"~"bb"~"20.25"~""~""~"0002"~"name" "dd"~"35.50"~"" ~""~"0003"~"name"~"aa"~"21.3 5"~""~""~ I want the output looking like: cat output.txt Code: "0001"~"name"~"bb"~"20.25"~""~""~... (6 Replies)
Discussion started by: mnmonu
6 Replies

4. Shell Programming and Scripting

Help for File Modification

Hi All, I have a file. This file contain huge amount of data. I want to modify this file. I want enter new line when count of "~ character is 79. Please find below the code : cat file_name | tr -d '\n' | sed... (6 Replies)
Discussion started by: mnmonu
6 Replies

5. Shell Programming and Scripting

Help for File Modification

Hi All, I have a file disk_space.log. cat disk_space.log 94% / 32% /boot 38% /mnt/data 100% /media/CDROM I want the output, like cat disk_space.log 94% / 100% /media/CDROM That means print the line those are grater-than 90%. And rest of the line is remove from file. I have a... (2 Replies)
Discussion started by: mnmonu
2 Replies

6. Shell Programming and Scripting

Help for File Modification

Hi, I have a file abcd.txt. cat abcd.txt output is as follows : "aa"~"bb"~"001"~""~""~"cc" "dd"~"005"~"" ~""~"kk"~"aa"~"00 8"~""~""~ I want the output looking like: cat abcd.txt "aa"~"bb"~"001"~""~""~ "cc""dd"~"005"~""~""~ "kk"~"aa"~"008"~""~""~ I have a script. (4 Replies)
Discussion started by: mnmonu
4 Replies

7. Shell Programming and Scripting

Help with file modification

Hi, I have a file test.txt . The contain of the file is as below : 365798~SAPUS~PR5~0000799005~ADM CHARG MEDCAL INS~~~~~~~~~~~~~~~~~~~~~~~~SLAC480 I want to modify this file. And file contain loking like "365798"~"SAPUS"~"PR5"~"0000799005"~"ADM CHARG MEDCAL... (6 Replies)
Discussion started by: mnmonu
6 Replies

8. Shell Programming and Scripting

File modification history

Can anyone please suggest an alternate command for "stat" . I am trying this on Solaris 5.9 , but the command doesn't exist. Basically i need to see one particalar file modification history. Any help is appreciated. (4 Replies)
Discussion started by: mk1216
4 Replies

9. UNIX for Dummies Questions & Answers

How to change the file modification time of a file on nfs mount point

Hi I am accessing a file on nfs mounted device, after completing using of the file, i am tring to restore the access time and modification times of the file. So i got the previous modified time of the file using stat() function and trying to set the date and time for the file, To set these... (6 Replies)
Discussion started by: deepthi.s
6 Replies

10. Shell Programming and Scripting

File modification

Dear all, i have a file which contains this lines. 0-0 CC=1 0-01 0-011 0-0111 0-01110 F=500 CC=1 L=15 M=5 TRD=3948... (2 Replies)
Discussion started by: panknil
2 Replies

Featured Tech Videos