Search a line and output next line as well

Hi,

I have a requirement to search a particular text and if found print next line also.

Appreciate your help.

Thanks

text=whatever
awk '/'"$text"'/ { print; n = 1; next }
n == 1 { print; n = 0 }'

Or sed:

sed -n '/text/{N;p}' file

HTH Chris

Where should I put file name. Thanks again, you are awesome!

I am getting following error:

sed -n '/Completed: ALTER DATABASE OPEN/{N;p}' alert_newdb.log
sed: Function /Completed: ALTER DATABASE OPEN/{N;p} cannot be parsed.

Thanks

(Asumming this is Linux)
Another though would be:
grep -b1 -a1 java /var/log/someserver.log

-b1 one line before "java"
-a1 one line following "java"

Sorry my mistake it is :
HP-UX B.11.11

My bad forgot to tell OS

sed -n '/Completed: ALTER DATABASE OPEN/{
N
p
}' alert_newdb.log

No! The options are -A and -B (and -C, to combine -A and -B).

They work for GNU grep which is standard in Linux and, apparently, *BSD.

Much simpler

text=start; awk '/'"$text"'/ { print; getline ; print $0; exit }' filename

Too verbose! :wink:

text=start; awk '/'"$text"'/{n=2}n-->0' filename