Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I want to catch all the lines between two matching regex lines from a file having lines as mentioned below in file loggs.txt . I've to capture the lines ...
  1. #1
    Just Joined!
    Join Date
    Jun 2006
    Posts
    40

    How to catch all the lines between two matching regex lines, into a temp file

    Hi,

    I want to catch all the lines between two matching regex lines from a file having lines as mentioned below in file loggs.txt. I've to capture the lines between two regex lines, as you can see in below output of :se nu of teh loggs.txt file, there are several lines between the regex lines.

    I've specified my regex line below. After capturing the lines between those two regex lines, I want to put those captured lines into a temp file.

    let for suppose:
    loggs.txt (my main file having all the lines, with :se nu output of the file)
    ------------------------------------------------------------------------------------------
    9 296~2009-05-06 02:55:28~[Timer-5]~ERROR~[management.manager.JvmOperationManager]~~An error occured while trying to get the Tomcat ThreadPool MBean at tribute 'currentThreadCount'. The exception was - java.lang.Exception: Unable to locate the Tomcat ThreadPool MBean
    10 java.lang.Exception: Unable to locate the Tomcat ThreadPool MBean
    11 at com.soa.framework.management.manager.JvmOperationM anager.getIntMBeanAttribute(JvmOperationManager.ja va:248...)
    12 at com..soa.framework.management.manager.JvmOperation Manager.getTomcatCurrentThreadCount(JvmOperationMa nager.java:216)
    13 at com.soa.framework.management.manager.JvmOperationM anager.updateStatistics(JvmOperationManager.java:1 36)
    14 at com.soa.framework.management.manager.JvmOperationM anager.pushStats(JvmOperationManager.java:125)
    15 at com.soa.framework.management.manager.JvmOperationM anager$UpdateTask.run(JvmOperationManager.java:173 )
    16 at java.util.TimerThread.mainLoop(Timer.java:512)
    17 at java.util.TimerThread.run(Timer.java:462)
    18 302~2009-05-06 02:55:28~[Timer-5]~ERROR~[management.manager.JvmOperationManager]~~An error occured while trying to get the Tomcat ThreadPool MBean at tribute 'currentThreadsBusy'. The exception was - java.lang.Exception: Unable to locate the Tomcat ThreadPool MBean
    19 java.lang.Exception: Unable to locate the Tomcat ThreadPool MBean
    20 at com.soa.framework.management.manager.JvmOperationM anager.getIntMBeanAttribute(JvmOperationManager.ja va:248....)
    21 at com.soa.framework.management.manager.JvmOperationM anager.getTomcatActiveThreadCount(JvmOperationMana ger.java:227)
    22 at com.soa.framework.management.manager.JvmOperationM anager.updateStatistics(JvmOperationManager.java:1 37)
    23 at com.framework.management.manager.JvmOperationManag er.pushStats(JvmOperationManager.java:125)
    24 at com.soa.framework.management.manager.JvmOperationM anager$UpdateTask.run(JvmOperationManager.java:173 )
    25 at java.util.TimerThread.mainLoop(Timer.java:512)
    26 at java.util.TimerThread.run(Timer.java:462)
    27 300~2009-05-06 02:55:32~[SOA-Bootstrap]~ERROR~[provider.enhanced.CacheMessagingService]~~Configuration propert jms.jndi.failover.ctx is not configure d.
    28 658~2009-05-06 02:55:32~[SOA-Bootstrap]~ERROR~[framework.container.ContainerImpl]~~ServiceGroup loader error - Reason: Cannot load HCI service group. Directory:[/runtime/RC01/library/hci-services] does not exist.
    29 212~2009-05-06 02:55:34~[SOA-Bootstrap]~ERROR~[framework.registry.DomainInfoImpl]~~Domain definition error on [HCIShopService]. Cause:c om.soa.services.configuration.ConfigurationExcepti on: File /webapps/B2BGateway/config/registry/services/service.config does not exist.
    ------------------------------------------------------------------------------------------

    The regex lines are those which starts with a pattern like:

    296~2009-05-06 02:55:28~[Timer-5]~ERROR~[management.manager.JvmOperationManager]~~
    #starting with numeric and then date, time and then ~~


    If I put a "search string" (lets say: error occured while trying to get the Tomcat ThreadPool MBean at) in my file and grep those search string lines from my file.....But as you see, for the matched line (line no. 9), their are some muliple lines after that matched line and then the next regex line comes at (line no. 18...).

    So, I want to capture the lines from line no. 9 to line no. 17 and then want to put those captured lines into any temp file ?

    Any help in this regard, will be highly appreciated. Thanks in advance

    Regards,
    Pawan Sangal

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    awk '/]~~/{++i}{print >> "file_"i}' file

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...