Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

grep...

  • 12-08-2002 01:57PM
    #1
    Registered Users, Registered Users 2 Posts: 513 ✭✭✭


    I'm trying to grep something from a file and i'm not too sure how, maybe someone has an idea on how to do this.

    The story is as follows:
    I have a file: file.log
    I want to grep lines of info from it, again and again. For example the lines might be:
    [B]ATDT123456[/B]
    info inbetween
    [B]pppd started[/B]
    info inbetween
    [B]ATDT654321[/B]
    info inbetween
    [B]pppd started[/B]
    
    the same over and over again...
    What I want to do is grep the lines in bold, over and over again, all down through the file.
    I think the best way might be to make a loop in a shell script but i'm not quite sure how to do it.

    Any suggestions?

    thanks in advance.

    C.


Comments

  • Registered Users, Registered Users 2 Posts: 4,660 ✭✭✭Gavin


    if it's linux (gnu grep) then you can use egrep as below

    egrep '^atdt | ^pppd' file.log

    Gav


  • Registered Users, Registered Users 2 Posts: 513 ✭✭✭Cond0r


    hmmm I tried that, and it didnt find any results , and it should have.
    It's in linux yeah, also gnu grep.
    What does the ^ do ?

    thanks!

    C.


  • Registered Users, Registered Users 2 Posts: 4,660 ✭✭✭Gavin


    it will only check for that word/expression at the start of the line.
    try removing them and see if it works ?
    failing that, just be lazy and do

    grep blah file.log ; grep blah2 file.log

    shocking poor way of doing it I know.

    Gav


  • Registered Users, Registered Users 2 Posts: 513 ✭✭✭Cond0r


    That works... but it's not exactly what I need...
    From the original post:
    [B]ATDT123456[/B]
    info inbetween
    [B]pppd started[/B]
    info inbetween
    [B]ATDT654321[/B]
    info inbetween
    [B]pppd started[/B]
    
    I need the output to look like this:
    ATDT123456
    pppd started <also has date here>
    ATDT654321
    pppd started <also has date here>
    
    Know what I mean? :(
    Tis annoying.

    C.


  • Registered Users, Registered Users 2 Posts: 8,345 ✭✭✭jmcc


    Originally posted by Verb
    if it's linux (gnu grep) then you can use egrep as below

    egrep '^atdt | ^pppd' file.log

    egrep -i '^atdt|^pppd' file.log>newfile

    The -i switch makes it case insensitive otherwise the grep would miss the ATDT unless you have:
    egrep '^ATDT|^pppd started'

    Regards...jmcc

    Regards…jmcc



  • Advertisement
  • Registered Users, Registered Users 2 Posts: 513 ✭✭✭Cond0r


    Excellent :D
    I played around with egrep read through the man and stuff, have it going nicely now!
    Thanks lads :)

    C.


Advertisement