Possible to grep string based on surrounding strings?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Possible to grep string based on surrounding strings?
# 15  
Old 05-16-2012
Quote:
Originally Posted by jl487
i understand that the script works for "REJECT" but how can this be modified to accept wildcards. For example, if input is:

Code:
titleA
titleB
TEST FILLER
titleC
TEST

and REJECT=TEST, I would expect the output to be just titleA. However, the current code outputs titleA, titleB, and TEST FILLER.
Just create a wrapper for the awk script posted by Corona688...this way you can tweak the REJECT value based on a shell parameter.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Single grep to multiple strings with separate output per string

I need to grep multiple strings from a particular file. I found the use of egrep "String1|String2|String3" file.txt | wc-l Now what I'm really after is that I need to separate word count per each string found. I am trying to keep it to use the grep only 1 time. Can you guys help ? ... (9 Replies)
Discussion started by: nms
9 Replies

2. 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

3. Shell Programming and Scripting

Need to print the next word from the same line based on grep string condtion match.

I need to fetch particular string from log file based on grep condition match. Actual requirement is need to print the next word from the same line based on grep string condtion match. File :Java.lanag.xyz......File copied completed : abc.txt Ouput :abc.txt I have used below... (5 Replies)
Discussion started by: siva83
5 Replies

4. Shell Programming and Scripting

Grep a part of file based on string identifiers

consider below file contents cat myOutputFIle.txt 8 CCM-HQE-ResourceHealthCheck: Resource List : No RED/UNKNOWN resource Health entries found ---------------------------------------------------------- 9 CCM-TraderLogin-Status: Number of logins: 0... (4 Replies)
Discussion started by: vivek d r
4 Replies

5. UNIX for Dummies Questions & Answers

Delete strings in file1 based on the list of strings in file2

Hello guys, should be a very easy questn for you: I need to delete strings in file1 based on the list of strings in file2. like file2: word1_word2_ word3_word5_ word3_word4_ word6_word7_ file1: word1_word2_otherwords..,word3_word5_others... (7 Replies)
Discussion started by: roussine
7 Replies

6. Shell Programming and Scripting

grep a string and print strings on that line

i have a file like below ABS 12234 A C 12G CFY 23865 A C 34D i want to grep "A C" then print ABS 12G 12234 CFY 34D 23865 Thanks! (4 Replies)
Discussion started by: kingpeejay
4 Replies

7. Shell Programming and Scripting

how to get surrounding lines of my grep search?

hi, if I grep a file, sometimes I want to see as an eg 2 lines above and below my grep results. how can this be done thanks (3 Replies)
Discussion started by: JamesByars
3 Replies

8. Shell Programming and Scripting

grep a string in the lines between 2 strings of a file

Hi , Please help me with the following problem: I have an xml file with the following lines <cisco:name> <cisco:mdNm>Cisco Device 7500 A Series</cisco:mdNm> <cisco:meNm>10.1.100.19</cisco:meNm> <cisco:ehNm>/shelf=1</cisco:ehNm> <cisco:subname> <cisco:sptp>Cisco PortA... (8 Replies)
Discussion started by: bhagirathi
8 Replies

9. 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

10. 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
Login or Register to Ask a Question
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)