Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Multiple Line search using grep Post 302232936 by pistachio on Friday 5th of September 2008 02:56:03 PM
Old 09-05-2008
Question cool!!

Thanks for the tip.But u just made me more interested in sed.

how will we do this then

The File looks like this
5012001,100,AUTOBATCH,FEE,DAILYFEE,0,0
4241 SERVICE DENIED
5012002,100,AUTOBATCH,FEE,DAILYFEE,0,0
4241 SERVICE DENIED
5012003,100,AUTOBATCH,FEE,DAILYFEE,0,0
4241 SERVICE DENIED
5012001,100,AUTOBATCH,FEE,DAILYFEE,0,0
2001 DIAMETER SUCCESS
5012002,100,AUTOBATCH,FEE,DAILYFEE,0,0
2001 DIAMETER SUCCESS
5012003,100,AUTOBATCH,FEE,DAILYFEE,0,0
2001 DIAMETER SUCCESS
5012001,100,AUTOBATCH,FEE,DAILYFEE,0,0
2001 DIAMETER SUCCESS
5012002,100,AUTOBATCH,FEE,DAILYFEE,0,0
2001 DIAMETER SUCCESS
5012003,100,AUTOBATCH,FEE,DAILYFEE,0,0


and i want the following output (containing numbers starting with only 50 in the first line have error code 4241 in the next line and thrid line containing number starting with 50 and fourth line having code 2001)


5012001,100,AUTOBATCH,FEE,DAILYFEE,0,0
4241 SERVICE DENIED
5012001,100,AUTOBATCH,FEE,DAILYFEE,0,0
2001 DIAMETER SUCCESS
5012002,100,AUTOBATCH,FEE,DAILYFEE,0,0
4241 SERVICE DENIED
5012003,100,AUTOBATCH,FEE,DAILYFEE,0,0
2001 SERVICE DENIED

Thanks
Pistachio
Image
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

multiple search with grep

is it possible to execute multiple search with grep??? grep criteria1 criteria2 file something like this... I know other way: grep pattern1 file-name1 > results-file grep pattern2 file-name1 >> results-file cat results-file but can it be done with one grep???? (5 Replies)
Discussion started by: amon
5 Replies

2. UNIX for Dummies Questions & Answers

search multiple words using grep

Hi frnds i want to desplay file names that should be word1 and word2 ex : i have 10 *.log files 5 files having word1 and word2 5 files having only word1, i have used below command egrep -l 'word1|word2' *.log its giving all 10 files, but i want to display only 5... (20 Replies)
Discussion started by: pb18798
20 Replies

3. Shell Programming and Scripting

multiple search keyword in grep

Dear All, I have a file containing info like TID:0903 asdfasldjflsdjf TID:0945 hjhjhkhkhkh TID:2045 hjhjhkhkhkh TID:1945 hjhjhkhkhkh TID:2045 hjhjhkhkhkh I need to show only lines containing TID:0903 asdfasldjflsdjf TID:0945 hjhjhkhkhkh TID:2045 hjhjhkhkhkh TID:2045 hjhjhkhkhkh ... (11 Replies)
Discussion started by: saifurshaon
11 Replies

4. Shell Programming and Scripting

Grep multiple search terms with context

I have a file that is a sort library in the format: ##def title1 content1 stuff1 content2 stuff2 ##enddef ##def title2 etc.. I want to grep def and content and pull some trailing context from content so the result would look something like: (1 Reply)
Discussion started by: Moe.Wilensky
1 Replies

5. Shell Programming and Scripting

Whether we can search multiple strings using or in grep -F

Hi, Whether we can search multiple strings using or in grep -F In Generally, grep -F "string1" "filename.txt" How to search for multiple string using grep -F as we using grep grep "string1\|string2" "filename.txt" Regards, Nanthagopal A (10 Replies)
Discussion started by: nanthagopal
10 Replies

6. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

7. Shell Programming and Scripting

Multiple line search, replace second line, using awk or sed

All, I appreciate any help you can offer here as this is well beyond my grasp of awk/sed... I have an input file similar to: &LOG &LOG Part: "@DB/TC10000021855/--F" &LOG &LOG &LOG Part: "@DB/TC10000021852/--F" &LOG Cloning_Action: RETAIN &LOG Part: "@DB/TCCP000010713/--A" &LOG &LOG... (5 Replies)
Discussion started by: KarmaPoliceT2
5 Replies

8. Linux

How to search multiple word using grep command?

How to search multiple word using grep command for example i want to reserch ANJ001 AA Using ridiculous font, size, and color changes instead of normal space separated text and CODE tags obfuscates what you are trying to do and makes it difficult for volunteers who may want to help you solve... (1 Reply)
Discussion started by: na.dharma
1 Replies

9. Shell Programming and Scripting

Search words in multiple file line by line

Hi All I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name. (4 Replies)
Discussion started by: netdbaind
4 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 is used to invoke the grep on compress'ed or gzip'ed files. All options specified are passed directly to grep. If no file is speci- fied, 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 zgrep is invoked as zegrep or zfgrep then egrep or fgrep is used instead of grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. For example: for sh: GREP=fgrep zgrep string files for csh: (setenv GREP fgrep; zgrep string files) AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), egrep(1), fgrep(1), zdiff(1), zmore(1), znew(1), zforce(1), gzip(1), gzexe(1) ZGREP(1)
All times are GMT -4. The time now is 06:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy