‘grep +A’: print everything after a match [duplicate]

AWK

If you don’t mind using AWK:

awk '/yahoo/{y=1;next}y' data.txt

This script has two parts:

/yahoo/ { y = 1; next }
y

The first part states that if we encounter a line with yahoo, we set the variable y=1, and then skip that line (the next command will jump to the next line, thus skip any further processing on the current line). Without the next command, the line yahoo will be printed.

The second part is a short hand for:

y != 0 { print }

Which means, for each line, if variable y is non-zero, we print that line. In AWK, if you refer to a variable, that variable will be created and is either zero or empty string, depending on context. Before encounter yahoo, variable y is 0, so the script does not print anything. After encounter yahoo, y is 1, so every line after that will be printed.

Sed

Or, using sed, the following will delete everything up to and including the line with yahoo:

sed '1,/yahoo/d' data.txt

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)