Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to grep a word and the two lines before? Post 302572253 by npatao71 on Wednesday 9th of November 2011 12:09:19 PM
Old 11-09-2011
How to grep a word and the lines before?

Hi

I have this txt file getting from a lpstat command.
Code:
XA40 XA40 0 Unknown 0 0 1 1 1
0 Unknown LPD 0 0 1 1 2
0 Unknown specified 0 0 1 1 3
XA99 @spip READY 
: (FATAL ERROR) 0781-233 Unknown host spiprs01.mon.local.
XA01 @xs00 READY 
XA01 XA01 0 Unknown 0 0 1 1 1
0 Unknown LPD 0 0 1 1 2
0 Unknown specified 0 0 1 1 3
XA07 @xs00 READY 
XA07 XA07 0 Unknown 0 0 1 1 1
0 Unknown LPD 0 0 1 1 2
0 Unknown specified 0 0 1 1 3
0 Unknown specified 0 0 1 1 3
0 Unknown 0 0 1 1 4
0 Unknown Status 0 0 1 1 5
0 Unknown 0 0 1 1 6
xA45 @diwp READY 
: (FATAL ERROR) 0781-233 Unknown host diwpsnt1.dgw.unix.com
XA32 @xs00 READY 
XA32 XA32 0 Unknown 0 0 1 1 1
0 Unknown LPD 0 0 1 1 2
0 Unknown 0 0 1 1 3
0 Unknown 0 0 1 1 4
0 Unknown Status 0 0 1 1 5
0 Unknown 0 0 1 1 6
XA64 @xs00 READY 
XA64 XA64 0 Unknown 0 0 1 1 1
0 Unknown LPD 0 0 1 1 2
 
XA10 @xs00 READY 
XA10 XA10 0 Unknown 0 0 1 1 1
0 Unknown LPD 0 0 1 1 2
0 Unknown specified 0 0 1 1 3
XA48 @xs00 READY 
XA48 XA48 0 Unknown 0 0 1 1 1
0 Unknown LPD 0 0 1 1 2
0 Unknown specified 0 0 1 1 3
XA68 @xs00 READY 
XA68 XA68 0 Unknown 0 0 1 1 1
0 Unknown LPD 0 0 1 1 2
0 Unknown specified 0 0 1 1 3
0 Unknown 0 0 1 1 4

How can i grep the word "ERROR" and the lines before (where are the id of the printer in error) and send the result to my mail?

Last edited by npatao71; 11-10-2011 at 06:30 AM.. Reason: Please use code tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

GREP:Output all lines containing word

Output all lines in the file temp that contain the word dog using GREP only and in one line!!! I tried grep ']dog]' temp but it doesnt catch word dog when is at beginning or end, like: Our dog is nice /this OK Nice dog /this NOT dog good /this NOT Thank... (3 Replies)
Discussion started by: ljubayuu
3 Replies

2. Shell Programming and Scripting

Word count of lines ending with certain word

Hi all, I am trying to write a command that can help me count the number of lines in the /etc/passwd file ending in bash. I have read through other threads but am yet to find one indicating how to locate a specifc word at the end of a line. I know i will need to use the wc command but when i... (8 Replies)
Discussion started by: warlock129
8 Replies

3. Shell Programming and Scripting

grep lines containing a word only twice.

Hi, I have a query on using grep options. I tried with several options but unable to do it. lanite:52> cat note 123 456 ab 123 ab cv 234 4566 67 ab gh tij ab 12 34 ab ab cv dfgv ab cv ab kjhk ab ghj sdf dfg ab jljklj ab Now, I need to use grep to find the line which contains the... (6 Replies)
Discussion started by: dilipr25
6 Replies

4. Shell Programming and Scripting

Search the word to be deleted and delete lines above this word starting from P1 to P3

Hi, I have to search a word in a text file and then I have to delete lines above from the word searched . For eg suppose the file is like this: Records P1 10,23423432 ,77:1 ,234:2 P2 10,9089004 ,77:1 ,234:2 ,87:123 ,9898:2 P3 456456 P1 :123,456456546 P2 abc:324234 (2 Replies)
Discussion started by: vsachan
2 Replies

5. Shell Programming and Scripting

grep part of word or Another word from a string

Hi all, FileOne family balance >>>>> 0 0 0 0 java.io.FileNotFoundException: Settings.xml (No such file or directory) at java.io.FileInputStream.open(Native Method) .. .... ..... ..... java.lang.NullPointerException ... ..... ...... Stacktrace: at... (2 Replies)
Discussion started by: linuxadmin
2 Replies

6. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

7. Shell Programming and Scripting

Need a word which just comes next to after grep of a specific word

Hi, Below is an example : ST1 PREF: int1 AVAIL: int2 ST2 PREF :int1 AVAIL: int2 I need int1 to come in preferred variable while programming and int2 in available variable Please help me doing so Best regards, Vishal (10 Replies)
Discussion started by: Vishal_dba
10 Replies

8. Shell Programming and Scripting

Grep word after last occurance of string and display next few lines

Hi, I wanted to grep string "ERROR" and "WORNING" after last occurrence of String "Starting" only and wanted to display two lines after searched ERROR and WORNING string and one line before. I have following cronjob log file "errorlog" file and I have written the code for same in Unix as below... (17 Replies)
Discussion started by: nes
17 Replies

9. Shell Programming and Scripting

How to print few lines before and after matching word is found suing grep?

Hi, here are few lines present in the logs. I want to grep on Error and print few lines before and after Error word is found line1 Line2 Line3 Error Line4 Line5 Line6 Line7 I want the output to be Line2 Line3 Error Line5 (1 Reply)
Discussion started by: arghadeep adity
1 Replies
PPI::Structure::Unknown(3)				User Contributed Perl Documentation				PPI::Structure::Unknown(3)

NAME
PPI::Structure::Unknown - An unknown or unresolved brace structure INHERITANCE
PPI::Structure::Unknown isa PPI::Structure isa PPI::Node isa PPI::Element DESCRIPTION
"PPI::Structure::Unknown" is class for braces whose type is unknown, or temporarily unknown. It primarily exists temporarily inside the lexer. Although some types of braces can be determined immediately at opening, there are a number of different brace types that can only be correctly identified after the braces are closed. A structure is typed as unknown during this period it is indeterminate. A "PPI::Structure::Unknown" object should not ever make it out of the lexer without being converted to it's final type. Any time you encounter this class in a PDOM tree it should be considered a bug and reported accordingly. METHODS
"PPI::Structure::Unknown" has no methods beyond those provided by the standard PPI::Structure, PPI::Node and PPI::Element methods. Got any ideas for methods? Submit a report to rt.cpan.org! SUPPORT
See the support section in the main module. AUTHOR
Adam Kennedy <adamk@cpan.org> COPYRIGHT
Copyright 2001 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.18.2 2011-02-25 PPI::Structure::Unknown(3)
All times are GMT -4. The time now is 02:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy