Find pattern; grep n lines before and after


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find pattern; grep n lines before and after
# 8  
Old 02-26-2017
It is well past my bed time, so I'm not going to try to come up with a solution to your problem right now, but I will note that your final sed script (if you used double quotes instead of single quotes, as I suggested before) will match:
Code:
[     12] 25/2/2017-19:02:06.996 frosti-3 M3UA-Tx:                   Data: 62 43 48 04 01 01 06 a6 6b 1a 28 18 06 07 00 11

in addition to matching the otid and dtid strings you want it to match. Since you have only shown us two records from your huge file, I have absolutely no idea how many other records might have this (or other) false matches for the way you're using to find pairs of matched records.

It is also interesting to note that the problem presented in post #1 in this thread is apparently unrelated to the problem presented here. Why the misdirect asking for a match on a tp-da value when what you're really looking for is a shared otid and dtid value filtered by part of a Source Address value? And, what keeps that part of a Source Address field from appearing in some other record's Source Address or Destination Address field? Are you sure the initial value you're looking for doesn't appear in some other field in your file as well?

Once you figure out what the otid value you're looking for is, do you know if the dtid value you need to match comes before or after the record containing the otid value? (If you know it comes after the value you've identified, it sure would be nice to just read your huge file once instead of reading the whole file more than three times.

How big is your "huge" file? Are we talking about megabytes, terabytes, or petabytes? How much memory do you have on your system?

What operating system and shell are you using?

Last edited by Don Cragun; 02-26-2017 at 06:59 AM.. Reason: Fix typos.
# 9  
Old 02-26-2017
You lost me. Are you looking for records containing
- tp-da : 0.1.078394420 and / or SSN: 6 GT: .85290985144?
- And then the otid value from within those to be matched with a dtid value? Or any other field's value?
- What is the sequence of otid / dtid, otid always first? Or last?
- Should otid records be printed regardless of dtid found or not?
- How many pairs will occur in one log file? Are they mixed up or in sequence?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep all lines with the pattern .sh

Linux version : Oracle Linux 6.5 Shell : bash In the the below text file (someString.text), I want to grep all lines with .sh in it. ie. Only the lines mysript.sh and anotherscript.sh should be returned. My below attempts failed. I gather that in regular expression world, dot (.) is the... (3 Replies)
Discussion started by: John K
3 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

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

4. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

5. Shell Programming and Scripting

Grep lines before a pattern having some other pattern

Hi All, I am trying to fetch lines before a pattern, I got to know about -B flag in grep but we have to pass the number to get those lines before some pattern say (X), now what if I want to get line/s with some other pattern say (Y) before X pattern? How to get about it? please help. Input:... (5 Replies)
Discussion started by: dips_ag
5 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

grep: get last 3 lines containing PATTERN from many files

Hi all, I am looking for a quick solution for this: I have many log files of an iterative program, and I would like to display the parameters of the last three iteration from each of those files. Relevant lines have the keyword: ITER I am using: tac ~/modeling*/fitting.log | grep -m 3 -e... (2 Replies)
Discussion started by: pnemeth
2 Replies

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

9. UNIX for Dummies Questions & Answers

Grep with 8 lines before and after pattern.

OK. I have a file I'd like to be able to grep, but on top of returning the line where the pattern matches, I'd like to be able to get the previous 8 lines and the following 8 lines. Is there a way to do this? (2 Replies)
Discussion started by: mrwatkin
2 Replies

10. Solaris

How to grep (say)last-3 and next-3 lines of Desired Pattern

Hi All, OS-Type=Sun-OS 5.8 Sparc9 Processor Can I grep the previous 4 lines and next 4 lines of a matched pattern(context grep)? For example here we need to monitor logs of live traffic.The data obtained from "tail -f LiveTrafficData.log" looks something like this:-... (3 Replies)
Discussion started by: Sujan Banerjee
3 Replies
Login or Register to Ask a Question