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

grep...

  • 12-08-2002 12: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,676 ✭✭✭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,676 ✭✭✭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: 7,521 ✭✭✭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


  • 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