using AWK see the upper lines and lower lines of the strings??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using AWK see the upper lines and lower lines of the strings??
# 1  
Old 10-07-2008
using AWK see the upper lines and lower lines of the strings??

Hi experts,

You cool guys already given me the awk script below-

awk '/9366109380/,printed==5 { ++printed; print; }' 2008-09-14.0.log

Morever, i have one more things-

when i awk 9366109380, i can also see the Upper 3 lines as well as below 5 lines of that string.

Line 1. <user>ability</user>
Line 2. <instance></instance>
Line 3. <context>sog.Administrator</context>
Line 4. <fullOperation>MAKE:NUMBER:9366109380:PPAY2;</fullOperation>
Line 5. <starttime>20081003000047</starttime>
Line 6. <stoptime>20081003000047</stoptime>
Line 7. <fullResult>940120105;;</fullResult>
Line 8. <status>FAILED</status>

//Purple
# 2  
Old 10-07-2008
You can use grep if your grep version supports the -A and the -B option otherwise:

Code:
awk '
/9366109380/ {
  print a[NR%3] "\n" a[(NR+1)%3] "\n" a[(NR+2)%3]
  print;getline;print;getline;print;getline;print;getline;print;exit
}
{a[NR%3]=$0}' file

Regards
# 3  
Old 10-07-2008
Guys Getting Error!!

bash-2.05$ awk '/9366109380/ { print a[NR%3] "\n" a[(NR+1)%3] "\n" a[(NR+2)%3] print;getline;print;getline;print;getline;print;getline;print;exit } {a[NR%3]=$0}' 2008.log

awk: syntax error near line 1
awk: illegal statement near line 1
# 4  
Old 10-07-2008
Use nawk or /usr/xpg4/bin/awk on Solaris.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: get upper and lower bound per group

Hi all, I've data as: 22 51018157 51018157 exonic CHKB nonsynonymous SNV 22 51018204 51018204 exonic CHKB nonsynonymous SNV 22 51018428 51018428 exonic CHKB nonsynonymous SNV 22 51018814 51018814 ... (4 Replies)
Discussion started by: genome
4 Replies

2. Shell Programming and Scripting

Lower to upper..tr + awk ?

I have a file that has a pattern 2 lines, blanktwo line If encountering the first line, the 2nd line need to be converted to UPPERCASE...or...conver the 2nd line after ablank into uppercase Is there a 'tr' function in awk..(probably the best tool over sed) ? i.e. ......................... (6 Replies)
Discussion started by: stevie_velvet
6 Replies

3. Shell Programming and Scripting

How to print lines that only have number lower than...

Hello guys, I am a beginner in Unix :wall: and was wondering if anyone could help me. I need a script that prints lines that only has Z-value lower than equals to (<=) 1.0e-02. Each column is seperated by a tab. 10009.fd Z-value = 3.62843e-03 10009.fd Z-value = 9.75489e-01... (3 Replies)
Discussion started by: narachaid
3 Replies

4. Shell Programming and Scripting

Print lines between two strings multiple occurencies (with sed, awk, or grep)

Hello, I can extract lines in a file, between two strings but only one time. If there are multiple occurencies, my command show only one block. Example, monfichier.txt contains : debut_sect texte L1 texte L2 texte L3 texte L4 fin_sect donnees inutiles 1 donnees inutiles 2 ... (8 Replies)
Discussion started by: theclem35
8 Replies

5. Shell Programming and Scripting

Sed or Awk for lines between two strings multiple times and keep the last one

Hi, I am trying to get lines between the last occurrences of two patterns. I have files that have several occurrences of “Standard” and “Visual”. I will like to get the lines between “Standard” and “Visual” but I only want to retain only the last one e.g. Standard Some words Some words Some... (4 Replies)
Discussion started by: damanidada
4 Replies

6. Shell Programming and Scripting

awk how to search strings within a file from two different lines

Hi, i would really appreciate any help anyone can give with the following info. Thanks in advance. I need to run a search on a file that contains thousands of trades, each trade is added into the file in blocks of 25 lines. i know the search has to take place between a time stamp specified... (4 Replies)
Discussion started by: sp3arsy
4 Replies

7. Shell Programming and Scripting

AWK: How to extract text lines between two strings

Hi. I have a text test1.txt file like:Receipt Line1 Line2 Line3 End Receipt Line4 Line5 Line6 Canceled Receipt Line7 Line8 Line9 End (9 Replies)
Discussion started by: TQ3
9 Replies

8. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

9. Shell Programming and Scripting

Grep and delete lines except the lines with strings

Hi I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings. Ex: file name 'test' test: approved package waiting for approval package disapproved package removed package approved... (14 Replies)
Discussion started by: vj8436
14 Replies

10. Shell Programming and Scripting

How to print only lines in between two strings using awk

Hi, I want to print only lines in between two strings and not the strings using awk. Eg: OUTPUT top 2 bottom 1 left 0 right 0 page 66 END I want to print into a new file only top 2 bottom 1 left 0... (4 Replies)
Discussion started by: jisha
4 Replies
Login or Register to Ask a Question