grep to list all lines after match

Posted on 2007-08-12
Last Modified: 2013-12-26
I'd like grep to output all lines after the first match (the matching line can also be included)

grep -A requires a numerical value of the number of lines (whereas I want all the remaining lines)

any ideas?  

tail +n  lists all lines after the nth line ..

so presumably theres a way to combine grep and tail to get all lines after the match

Question by:nsriram
    LVL 38

    Accepted Solution

    You can do :

    tail +n`grep -n string filename | head -1 | cut -f1 -d' '| tr -d :` filename

    Author Comment

    I found that simply giving a number that was larger than the number of lines in the file did the job..
    I will try yours as well although its hard for a newbie me to fully follow. I do realize that the backtick is for commands

    grep -A 1000000 string filename

     seems to work (assuming 1000000 is larger than the maxlines in the file)

    LVL 38

    Expert Comment

    You can use:
    wc -l filename
    to find out the nubmer of lines in the file.

    Author Comment

    thanks.. I also understand your solution.. maybe you can take a shot at my date question as well :-)
    LVL 38

    Expert Comment

    >>maybe you can take a shot at my date question as well :-)

    Could you please post the link to your date question, I'll give it a try.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now