Sponsored Content
Top Forums Shell Programming and Scripting how to get surrounding lines of my grep search? Post 302350831 by Scrutinizer on Saturday 5th of September 2009 04:40:26 PM
Old 09-05-2009
Code:
grep -B2 -A2

-B before
-A after
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How can you show lines surrounding a search string?

I would like to be able to grep (or some such thing) a search argument and then display the line plus the preceding 3 lines of the file and the following 3 lines of the file. Any ideas? Thanks in advance! :D (3 Replies)
Discussion started by: robster
3 Replies

2. Shell Programming and Scripting

Surrounding a chunk of code by #ifdef and #endif

Hello the great gurus :) I'm quite new to this, so perhaps I'm asking a simple and trivial question (which is good, because you'll answer for sure :)))) Anyway. I have an amount of *.c files (about 100), and what I want to do, is to surround a specific function call with #ifdef and #endif. ... (6 Replies)
Discussion started by: xxxaxa
6 Replies

3. UNIX for Dummies Questions & Answers

View all lines in grep search

I am trying to grep a file and I need to show the schedules that the grep belongs too. here is the command I am using and the result I am getting: $ fgrep -e 'SCALHOL' twsschedules EXCEPT SCALHOL -1 DAYS EXCEPT SCALHOL -1 DAYS EXCEPT SCALHOL -1 DAYS ... (1 Reply)
Discussion started by: wereyou
1 Replies

4. Shell Programming and Scripting

how to get surrounding lines of grep result

hi, if i have a file and i want to search for the word error using grep, i usually want to see the surrounding lines too as they contain info about the error. what would be a nice way to achieve this? thanks (6 Replies)
Discussion started by: JamesByars
6 Replies

5. Shell Programming and Scripting

Perl XML, find matching condition and grep lines and put the lines somewhere else

Hi, my xml files looks something like this <Instance Name="New York"> <Description></Description> <Instance Name="A"> <Description></Description> <PropertyValue Key="false" Name="Building A" /> </Instance> <Instance Name="B"> ... (4 Replies)
Discussion started by: tententen
4 Replies

6. Shell Programming and Scripting

search and replace, when found, delete multiple lines, add new set of lines?

hey guys, I tried searching but most 'search and replace' questions are related to one liners. Say I have a file to be replaced that has the following: $ cat testing.txt TESTING AAA BBB CCC DDD EEE FFF GGG HHH ENDTESTING This is the input file: (3 Replies)
Discussion started by: DeuceLee
3 Replies

7. Shell Programming and Scripting

Possible to grep string based on surrounding strings?

I was wondering if it was possible to grep a pattern based on the surround text. For example, if i have an input file like this: titleA titleB titlex titleC titleD titlex titleE And I want to grep "title" and save the results only if it is not followed with a "titlex". My output... (14 Replies)
Discussion started by: jl487
14 Replies

8. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

9. Shell Programming and Scripting

Grep pattern only and surrounding lines

Hello, I am trying to grep search a pattern and a line before it. cat input >record1 hello1hello2hellonhello3 >record2 helloohello1hello2hello3 When I use, grep with -o option and either of -A/B/C options, I still can't see lines before or after the pattern. But the exact pattern is... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

10. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 08:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy