grep -A 1 "string" filename

Dear all,

can anyone pls provide equivalent of below code for solaris system.?

grep -A 1 "string" filename  

the above command is working for Linux system. but i need same command for Solaris system

thanks

awk '/string/{print;getline;print}' filename
# sed -n '/max/{N;p}' infile

To make these solutions also work for a match on the last line:

sed -n '/string/{$!N;p}' infile
awk '/string/{print;if(getline)print}' infile

Hi rdcwayx,

awk '/string/{print;getline;print}' filename

the above command it not working when we put in cron jobs in solaris server.

pls suggest me alter command for the same.

Thanks :slight_smile:

If your system is solaris, use /usr/bin/nawk or /usr/xpg4/bin/awk

Hi rdcwayx,

pls check the below script is correct?

its not working. pls help !!!!!

#!/usr/xpg4/bin/awk
tm=`TZ=GMT date +%H`
awk '/^$tm:/{print;getline;print}' af02_alarm_log.31082010  > /tmp/HLR_alarm.txt

i'm grep the string starts with current system time "^$tm:"

---------- Post updated at 04:45 PM ---------- Previous update was at 09:57 AM ----------

can anyone help me on this issue.?

the mentioned script is not working. pls help...!!!

Thanks

Try:

#!/bin/sh
tm=`TZ=GMT date +%H`
/usr/xpg4/bin/awk "/^$tm:/{print;if(getline)print}" af02_alarm_log.31082010  > /tmp/HLR_alarm.txt

or alternatively replace last line with:

/usr/xpg4/bin/sed -n "/$x/"'{$!N;p}' af02_alarm_log.31082010  > /tmp/HLR_alarm.txt
1 Like

Dear Scrutinizer,

Thank you so much.. it working fine..

Thanks

Br//
Steve