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

Some scripting help needed

  • 27-06-2008 7:25pm
    #1
    Registered Users, Registered Users 2 Posts: 6,949 ✭✭✭


    Hi guys, scripting isnt my strongpoint but im pretty sure it would be a cakewalk for a regular.

    I need a script to grep an IP address from the end of a log file, backwards until it finds 10 matches or hits the start of the logfile. The IP address that I am look for will change with each search of course. Output to screen is fine.

    Any ideas?


Comments

  • Registered Users, Registered Users 2 Posts: 52 ✭✭Jamar


    Perhaps I'm missing something, but

    grep '10.10.10.10' logfile | tail -10


  • Closed Accounts Posts: 1,467 ✭✭✭bushy...


    Maybe you could do something with tac ?
    #!/bin/bash
    tac   logfile | grep $1 | head -10
    


  • Registered Users, Registered Users 2 Posts: 868 ✭✭✭brianmc


    Jamar wrote: »
    Perhaps I'm missing something, but

    grep '10.10.10.10' logfile | tail -10

    I like this one.

    I'd change it to backslash the dots in the IP address though.

    Perhaps there's an option to grep to ignore regular expression characters?


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    brianmc wrote: »
    I like this one.

    +1. Clever.


  • Closed Accounts Posts: 37 Arion


    brianmc wrote: »
    I like this one.

    I'd change it to backslash the dots in the IP address though.

    Perhaps there's an option to grep to ignore regular expression characters?

    fgrep or grep -F


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 6,949 ✭✭✭SouperComputer


    Thanks for all the input guys. I went with tac in the end. So simple, cant believe Ive never come across it!


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Just "man tac"'d. Never come across it before either. Useful to know.

    To save anyone else the hassle.....
    NAME
           tac - concatenate and print files in reverse
    
    SYNOPSIS
           tac [OPTION]... [FILE]...
    
    DESCRIPTION
           Write  each FILE to standard output, last line first.  With no FILE, or
           when FILE is -, read standard input.
    


Advertisement