Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Grep and display n lines after the match is found. Post 302240371 by Franklin52 on Thursday 25th of September 2008 02:32:55 PM
Old 09-25-2008
Quote:
Originally Posted by cv_pan
Hello,
How do I use grep to find a pattern in a list of file and then display 5 lines after the pattern is matched

Eg:
I want to match the string GetPresentCode in all files in a folder and then see 4 lines following this match. I am not sure if grep is what should be used to achieve. Thanks!


#Method
GetPresentCode Behaviours
#Return Type
string
#Method Body
return pPresent.code
#User Tags
_DI_LABEL = editonly "--_Transaction code?"
_DI_DESCRIPTION = editonly ""
_DI_TYPE = editonly "Condition"

output as:
GetPresentCode Behaviours
#Return Type
string
#Method Body
return pPresent.code
With awk:

Code:
awk '/GetPresentCode/{c=5;next}c{c--;print}' file


Last edited by Franklin52; 09-25-2008 at 03:47 PM.. Reason: adding first opening brace, thanks era ;-)
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to prevent grep command from throwing a system trap if No match is found.

Hi How to prevent grep command from throwing a system trap(or returning error status) if No match is found in the specified file(s) ? Consider this simple shell script: #!/usr/bin/ksh trap 'STATUS=$?;set +x;echo;echo error $STATUS at line nb $LINENO executing :\ `sed -n... (2 Replies)
Discussion started by: cool.aquarian
2 Replies

2. Shell Programming and Scripting

How to grep for message and if found display filename?

Hi i'm new to the forum and was hoping someone could help me with the following query. I do alot of testing and have hundreds of log files output. I have a script (someone else wrote) which finds all the passed and failed logs and puts a number in a column onto a webpage: e.g: Pass ... (4 Replies)
Discussion started by: defamer
4 Replies

3. Shell Programming and Scripting

kill a process if grep match is found

Hi, I need something unusual, I guess. I need to start a process, and if that process displays a specific error message, I need to kill that process and restart it. Something like: startprocess | grep -i "This is the specific error message" && kill $pidof(startprocess) Explanation, I need... (4 Replies)
Discussion started by: burek
4 Replies

4. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

5. UNIX for Dummies Questions & Answers

Display n lines before match found

I have a file with following data A B C D E F G H I K L M N and search pattern is G Expected output (3 Replies)
Discussion started by: nsuresh316
3 Replies

6. UNIX for Dummies Questions & Answers

Display n lines after match found and other line

I have a file like this DoctorName Address1 Address2 DOB InsuredName Address1 Address2 DOB PatientName Address1 Address2 DOB ClaimNo1 DoctorName Address1 Address2 DOB InsuredName (2 Replies)
Discussion started by: nsuresh316
2 Replies

7. UNIX for Dummies Questions & Answers

Display lines after match is found within specified range

I have a file which has collection of segments occuring n(For eg.100) times ISA GS ST NM1*85 N3 N4 NM1*IL N3 N4 REF*D9*1001 ISE GE SE ISA GS ST NM1*85 N3 (13 Replies)
Discussion started by: nsuresh316
13 Replies

8. Shell Programming and Scripting

Grep multiple exact match, do not display lines

Hi, Need help to grep the following from a file x. I just want to grep exact match not lines and not partial word. CONFSUCCESS CONFFAIL CONFPARTIALSUCCESS >cat x xczxczxczc zczczcxx CONFSUCCESS czczczcczc czxxczxzxczcczc CONFFAIL xczxczcxcczczc zczczczcz CONFPARTIALSUCCESS czczxcxzc ... (4 Replies)
Discussion started by: rajeshwebspere
4 Replies

9. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

10. Shell Programming and Scripting

Grep everything between two pattern if match not found

I need to help to work this Print everything between 2 patterns if grep is not found the search word example Detroit orange cat bat rat apple sed -n "/Detroit,/apple/p" d |grep chicago output would be Detroit orange cat bat rat (1 Reply)
Discussion started by: jhonnyrip
1 Replies
Class::MOP::Method::Wrapped(3)				User Contributed Perl Documentation			    Class::MOP::Method::Wrapped(3)

NAME
Class::MOP::Method::Wrapped - Method Meta Object for methods with before/after/around modifiers VERSION
version 2.1202 DESCRIPTION
This is a Class::MOP::Method subclass which implements before, after, and around method modifiers. METHODS
Construction Class::MOP::Method::Wrapped->wrap($metamethod, %options) This is the constructor. It accepts a Class::MOP::Method object and a hash of options. The options are: o name The method name (without a package name). This will be taken from the provided Class::MOP::Method object if it is not provided. o package_name The package name for the method. This will be taken from the provided Class::MOP::Method object if it is not provided. o associated_metaclass An optional Class::MOP::Class object. This is the metaclass for the method's class. $metamethod->get_original_method This returns the Class::MOP::Method object that was passed to the constructor. $metamethod->add_before_modifier($code) $metamethod->add_after_modifier($code) $metamethod->add_around_modifier($code) These methods all take a subroutine reference and apply it as a modifier to the original method. $metamethod->before_modifiers $metamethod->after_modifiers $metamethod->around_modifiers These methods all return a list of subroutine references which are acting as the specified type of modifier. AUTHORS
o Stevan Little <stevan.little@iinteractive.com> o Dave Rolsky <autarch@urth.org> o Jesse Luehrs <doy@tozt.net> o Shawn M Moore <code@sartak.org> o XXXX XXX'XX (Yuval Kogman) <nothingmuch@woobling.org> o Karen Etheridge <ether@cpan.org> o Florian Ragwitz <rafl@debian.org> o Hans Dieter Pearcey <hdp@weftsoar.net> o Chris Prather <chris@prather.org> o Matt S Trout <mst@shadowcat.co.uk> COPYRIGHT AND LICENSE
This software is copyright (c) 2006 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.18.2 2014-01-19 Class::MOP::Method::Wrapped(3)
All times are GMT -4. The time now is 09:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy