grep -A 1 "string" filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting grep -A 1 "string" filename
# 1  
Old 08-26-2010
grep -A 1 "string" filename

Dear all,

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

Code:
grep -A 1 "string" filename

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

thanks
# 2  
Old 08-26-2010
Code:
awk '/string/{print;getline;print}' filename

# 3  
Old 08-26-2010
Code:
# sed -n '/max/{N;p}' infile

# 4  
Old 08-26-2010
To make these solutions also work for a match on the last line:
Code:
sed -n '/string/{$!N;p}' infile

Code:
awk '/string/{print;if(getline)print}' infile


Last edited by Scrutinizer; 08-26-2010 at 03:55 AM..
# 5  
Old 09-01-2010
Hi rdcwayx,

Code:
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 Smilie
# 6  
Old 09-01-2010
If your system is solaris, use /usr/bin/nawk or /usr/xpg4/bin/awk
# 7  
Old 09-01-2010
Hi rdcwayx,

pls check the below script is correct?

its not working. pls help !!!!!

Code:
#!/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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep all lines with the string "TNS-" but skip those with "TNS-12514"

Platform: Oracle Linux 6.3 From a log file, I want to grep all lines with the pattern "TNS-" but I want to skip those with the pattern "TNS-12514" . How can I do this ? (3 Replies)
Discussion started by: John K
3 Replies

2. Shell Programming and Scripting

grep with "[" and "]" and "dot" within the search string

Hello. Following recommendations for one of my threads, this is working perfectly : #!/bin/bash CNT=$( grep -c -e "some text 1" -e "some text 2" -e "some text 3" "/tmp/log_file.txt" ) Now I need a grep success for some thing like : #!/bin/bash CNT=$( grep -c -e "some text_1... (4 Replies)
Discussion started by: jcdole
4 Replies

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. UNIX for Dummies Questions & Answers

"tail -n 1 filename" error while "head -n 1 filename" is ok?

Hi all, I was wondering why tail -n 2 filename produce an error when I manage to do similar command on head -n 2 filename SunOS{type8code0}: tail -n 2 filename usage: tail ] tail ] (2 Replies)
Discussion started by: type8code0
2 Replies

5. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

6. UNIX for Dummies Questions & Answers

the meaning of "!:*" in "alias foo 'command\!:*' filename"

Hi: How can I remove my own post? Thanks. (2 Replies)
Discussion started by: phil518
2 Replies

7. UNIX for Dummies Questions & Answers

search excat string in another string (grep "fails")

hello, i have an statement which i have to correct because it shows the wrong result. i want to search an excat string in another string, command "grep" shows the wrong result: example: STRINGS="string1 string2 string3" search_string="string" incorrect: if then echo "not... (0 Replies)
Discussion started by: bora99
0 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. Shell Programming and Scripting

Unix shell script (grep -A 6 -B 2 "ORA-" filename

BACKGROUND: I am using Solaris 10. Some of my boxes have gnu grep and I can use -A and -B flags on those. However, the solaris flavor of grep won't use the flags -A or -B. And some of my boxes won't be getting gnu grep. Should I try using perl, awk, or sed? Actual PROBLEM: I am... (7 Replies)
Discussion started by: el_guero
7 Replies

10. UNIX for Dummies Questions & Answers

correct syntax for using "grep regex filename" ?

I'm trying to grep a long ls by looking at the beginning of each filename for example: Many files begin with yong_ho_free_2005... Many files begin with yong_ho_2005... I can't just use "grep yong_ho" otherwise It'll display both files. So I'm trying to use a regex but my syntax is wrong. ... (2 Replies)
Discussion started by: yongho
2 Replies
Login or Register to Ask a Question