Find the answer to your Linux question:
Results 1 to 3 of 3
Dear Experts, I am new to shell scripting. I am trying to create a shell script to capture the strings mentioned as bold in below file. Can we use "sed" ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2006
    Posts
    40

    Can we do string capturing this using sed or awk ?


    Dear Experts,

    I am new to shell scripting. I am trying to create a shell script to capture the strings mentioned as bold in below file.

    Can we use "sed" or "awk" ? to capture some string from my line. let's say I've a file having some lines as below:
    msgfile.txt # :se nu ouput of teh file
    --------------------------------------------------------------------------------------------------
    1 WARN~[Caching Utility]~~Transaction Stats Monitoring Property not found. Default will be used: 30000
    2 WARN~[handlers.authcache.AuthCacheHandler]~EAS/Processor22_241578842031~Security cache messaging resource could not be
    retrieved. The resource may not be configured or is configured incorrectly
    .
    WARN~[RuntimeException]~TDSWS/Processor36_1241585939~RuntimeException request data - AgK82dU25dN9uDlnMHaT/uD3wTtrVvf0AxPucVDQ5bqK4t+PgT3XZ7ramK5XmfHSEG8uE7R 3iaQWtMVjgTAq/2tImsgoC66842OjucurKu0LjA1aNdcSsnO1T69kbNGVY5SvCSX ygoOsEUhNVYqB9VqeIxLyOdxYj/b8RWUJM5mYeh0/2Z21XjU2akTNSQa7qGFmV7p427mlffl4W0CBxkXCqpE0WzJ3q4 HngXZonoU2be85FRrritB7YacSE/3dcJP2dmP/m27GeT52QT7h0STtX854XKgLg8fXV/6SnsE/5OJSZSTJE79xIbms6TVzMLBwXijJxtRtcYzWTE3ZgiHnhNIguo 7B2k8JOKiGZaQ3oECGruKTF3DINQfMBqIdE3OGo3hDn4rB - End of RuntimeException request data

    3 WARN~[secrp.db2.Dyngtid1DAOImpl]~~GTID Get result for SAP = 00004
    4 WARN~[secrp.db2.Dyngtid1DAOImpl]~~GTID Get result for SGP = 00004

    5 WARN~[xws.processing.TransactionManager]~TDSWS/Processor6_12491789044~XWS Request Failed. Original request is: <EndSession bdmVersion="0.0" version="1.0" xmlns="http://wbserv.com"><Token/></EndSession> Error Message: Host Access Service Session Token Must be populated. Value Passed in = .

    6 ERROR~[framework.dataaccess.DASDataSourceImpl]~~Check server.xml datasource DASDatasource
    7 ERROR~[datamanager.cache.SessionFilesCache]~~FileWriterUtility: Error reading / deleting file /projects/service_storage/AccessService/app1_

    8 ERROR~[management.manager.JvmOperationManager]~~An error occured while trying to get the Tomcat ThreadPool MBean attribute 'currentThreadsBusy'. The exception was - java.lang.Exception: Unable to locate the Tomcat ThreadPool MBean

    9 ERROR~[datamanager.pool.DynamicGtidLoader]~~java.lang.Exception: Error occured while loading dynamic Gtids into pool from database. No Dynamic Gtids are Available.

    10 ERROR~[socketmanagement.queue.IncommingHostMessageQueue]~~Non Final Message. Can't find the item in the Queue for message Key: + 00034469 Message = SSR0100034469PRR01000103N00DOT011425080302299K 000052GFRH000F00030000NNNNYNNYYNNNNNNNNNNNNNNNN400 052850000100

    11 ERROR~[framework.management.ProxyMBean]~~Operation 'TURN_OFF_REQUESTOR' threw exception - java.lang.RuntimeException: All services are busy for operation 'TURN_OFF_REQUESTOR'. Discarding this invocation.

    12 ERROR~[framework.management.ProxyMBean]~~ProxyMBean.invoke() caught an exception - java.lang.reflect.InvocationTargetException

    13 ERROR~[framework.container.ContainerImpl]~~Service [SuperSearchSPNRService:ver=1.0:sla=1:remote=false] depends on undefined or misconfigured service [ListSPNRService:ver=1.0:sla=1] com.cendant.tds.soa.services.configuration.Configu rationException: File /projects/webapps/B2BGateway/config/registry/services/ListSPNRService/1/service.config does not exist.

    14 FATAL~[hostaccessservice.util.FileWriterUtility]~TDSWS/Processor17_12407469452 *~TRY_LOCK ALERT: Retry #1 File Name: /proje
    cts/AccessService/session/SDC180000T907249548
    15 FATAL~[hostaccessservice.util.FileWriterUtility]~TDSWS/Processor17_12407469452 *~TRY_LOCK ALERT CORRECTED (Lock Obtained):
    Retry #2 File Name: /projects/AccessService/session/SDC180000T907249548
    --------------------------------------------------------------------------------------------------

    I want to capture above strings mentioned in bold which are in between my lines. I tried to capture the string which are starting after the "~~" or "~" after a "]" literal.

    I used:
    ---------
    cat msgfile.txt|sed 's/\(.*~~*\)//;s/\([a-zA-Z0-9 \t][a-zA-Z0-9 \(\)\.\t]*\)[ :-\.].*/\1/'|more

    But, I think its not working for all of the lines, I think I've to refine my sed parameters, so as to retreive all the strings mentioned above in bold.

    Can anybody help me, If this can be acheived using sed or awk ?

    Any help, will be highly appreciated.

    Thanks-
    Pawan

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    here's something in Python.
    Code:
    #!/usr/bin/env python
    for line in open("file"):
        oline=line.strip()
        line=oline.split()
        try:
            if line[0].isdigit():
                if "*~" in oline:
                    ind=oline.index("*~")            
                elif "~~" in oline:
                    ind=oline.index("~~")                  
                print oline[ind:]
        except Exception,e:pass

  3. #3
    Just Joined!
    Join Date
    Jun 2006
    Posts
    40
    Quote Originally Posted by ghostdog74 View Post
    here's something in Python.
    Code:
    #!/usr/bin/env python
    for line in open("file"):
        oline=line.strip()
        line=oline.split()
        try:
            if line[0].isdigit():
                if "*~" in oline:
                    ind=oline.index("*~")            
                elif "~~" in oline:
                    ind=oline.index("~~")                  
                print oline[ind:]
        except Exception,e:pass
    Thanks......I am totally a rookie to Python scripting, so don't know how much it'll help me, but thanks for providing a solution against my problem.

    Regards,
    Pawan

  4. $spacer_open
    $spacer_close

Posting Permissions

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