1

what command would I use to see all lines from a file starting with a line that I find with grep

so I imagine something like a tail, but beginning from a line that I identify with a grep.

For example I am looking at a log and I can identify a point that has a time in it. So I want to see all log lines that come after the log line that contains a particular date time.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
sdfor
  • 113
  • 3

2 Answers2

3

this should do it:

sed -n -e "/pattern/,\$p" filename
MelBurslan
  • 6,836
  • 2
  • 24
  • 35
1

The -A option for grep can do this. Normal usage is for context after matches, and -B for context before matches. The -m option limits the number of matches.

grep -A1000000 -m1 <search> <file>

will output up to 1000000 trailing lines of context (and to make this work just ensure the number is greater than the number of lines in the file -- and if your file is more than 1000000 lines long, grep is probably not the right tool). In a similar fashion,

grep -B1000000 -m1 <search> <file>

will print out all lines up to and including the first match. (This is not, to my knowledge, the intended use of these options, but is a natural side-effect of how they work: the alternative is to use a program other than grep.)

John Allsup
  • 236
  • 1
  • 5
  • No need for one billion lines of context and yes, you can do it with `gnu grep` regardless of the no. of lines in your input: `{ grep -m1 pattern; cat; } – don_crissti Feb 19 '16 at 17:23
  • @don_crissti Do I get this properly: `grep` will stop reading the file after the first match and the rest will be displayed because `cat` takes over the rest of the input since the whole file is passed to the group? – FelixJN Feb 19 '16 at 18:50
  • 1
    @Fiximan - that is correct buddy, [see _mikeserv_'s explanation here](http://unix.stackexchange.com/a/208696) (this question is almost a duplicate of that one) – don_crissti Feb 19 '16 at 18:56