Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

shell script -parsing a log file

  • 10-01-2002 2:35am
    #1
    Registered Users, Registered Users 2 Posts: 5,741 ✭✭✭


    Any one some quick ideas on this?
    I basically want to find the first occurrence of a pattern in a log file and then manipulate the rest of the file from there on eg a date stamp-dumping into another temp file would be ok..
    jd


Comments

  • Moderators, Social & Fun Moderators Posts: 10,501 Mod ✭✭✭✭ecksor


    I'm almost certain that sed can do this by specifying the pattern you want as the first range parameter to whatever operator you're using. That may or may not be helpful though.

    something like
    cat $filename |
    ( flag=""
      while read logline
      do
           if echo $logline | grep "pattern" > /dev/null
           then
                 flag="X"
           fi
    
            if [ "$flag" = "X" ]
            then
                 echo $logline
            fi
       done) | tr a A
    

    Would turn all lowercase a to A in a file starting with the line where "pattern" occured.


  • Registered Users, Registered Users 2 Posts: 171 ✭✭Wookie


    Given a file called test.txt

    wookie
    wookie
    marker
    hello world
    hello world

    run test.com

    T1=`grep -n marker ./test.txt | cut -f 1 -d : -`
    T2=`cat test.txt | wc -l`
    T3=$(($T2 - $T1))
    tail -$T3 test.txt > new.txt

    new.txt should then contain the following

    hello world
    hello world

    I think this does what you need. However it is probably two much of a hack to ever be used.


  • Registered Users, Registered Users 2 Posts: 5,741 ✭✭✭jd


    Originally posted by Wookie
    Given a file called test.txt

    wookie
    wookie
    marker
    hello world
    hello world

    run test.com

    T1=`grep -n marker ./test.txt | cut -f 1 -d : -`
    T2=`cat test.txt | wc -l`
    T3=$(($T2 - $T1))
    tail -$T3 test.txt > new.txt

    new.txt should then contain the following

    hello world
    hello world

    I think this does what you need. However it is probably two much of a hack to ever be used.

    yes that was something like I was trying..
    I made one change to make it work though

    T1=`grep -n marker ./test.txt | cut -f 1 -d : - |head -1 - `
    tx
    jd


Advertisement