Find pattern which goes over a CR


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find pattern which goes over a CR
# 1  
Old 11-17-2016
Find pattern which goes over a CR

As most of the tools grep/awk are line based I'm not sure how to find a pattern in a file which goes over multiple lines, without truncating or changing the file before.
What's the most effective way to find the exact pattern which contains out of 2 lines without a regex like .*\n within a sed:
Code:
1 | 1 | ERR
LIST

Moderator's Comments:
Mod Comment Use code tags, thanks.

Last edited by zaxxon; 11-17-2016 at 05:27 AM..
# 2  
Old 11-17-2016
You could substitute the newlines while processing. Something like this?

Code:
$ cat infile
1 | 1 | ERR
LIST
2 | 2 | ERROR
LIST
3 | 3 | ERR
LIST
$ sed -ne '/ERR$/ {N; s/\n//g; p}' infile
1 | 1 | ERRLIST
3 | 3 | ERRLIST

# 3  
Old 11-17-2016
Hi,
If your grep support this:
Code:
grep -Pzo '1 \| 1 \| ERR\nLIST' file

Regards.
# 4  
Old 11-17-2016
Hi.

Perhaps of some help, but may require acquisition and compiling:
Code:
Match patterns, strings across lines

        1) cgrep
           https://sourceforge.net/projects/cgrep/

        2) peg
           http://www.cpan.org/authors/id/A/AD/ADAVIES/peg-3.10 (or later)

        3) bool
           https://www.gnu.org/software/bool/

        4) sift (aka "gogrep")
           https://sift-tool.org/ (verified 2015.11.05)

Some details:
Code:
cgrep   shows context of matching patterns found in files (man)
Path    : ~/executable/cgrep
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)

peg     Perl version of grep, q.v. (what)
Path    : ~/bin/peg
Length  : 4749 lines
Type    : Perl script, ASCII text executable
Shebang : #!/usr/bin/env perl
Help    : probably available with --help

bool    print context matching a boolean expression (man)
Path    : ~/executable/bool
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
Help    : probably available with [     ]-h,--help

gogrep  Match, grep-like, alternate name for "sift" (man)
Path    : ~/executable/gogrep
Type    : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
Help    : probably available with --help

Best wishes ... cheers, drl

Last edited by drl; 11-17-2016 at 07:56 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find a pattern and traverse left and pick something from another pattern

I have a Text like below , Detailed Table Information Table(tableName:a1, dbName:default, owner:eedc_hdp_s_d-itm-e, createTime:1520514151, lastAccessTime:0, retention:0, sd:StorageDescriptor(cols:, location:hdfs://DBDP-Dev/apps/hive/warehouse/a1,... (6 Replies)
Discussion started by: nv186000
6 Replies

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

3. UNIX for Dummies Questions & Answers

Find pattern suffix matching pattern

Hi, I am trying to get a result out of this but fails please help. Have two files /tmp/1 & /tmp/hosts. /tmp/1 IP=123.456.789.01 WAS_HOSTNAME=abcdefgh.was.tb.dsdc /tmp/hosts 123.456.789.01 I want this result in /tmp/hosts if hostname is already there dont want duplicate entry. ... (5 Replies)
Discussion started by: rajeshwebspere
5 Replies

4. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

5. UNIX for Dummies Questions & Answers

find Search - Find files not matching a pattern

Hello all, this is my first and probably not my last question around here. I do hope you can help or at least point me in the right direction. My question is as follows, I need to find files and possible folders which are not owner = AAA group = BBB with a said location and all sub folders ... (7 Replies)
Discussion started by: kilobyter
7 Replies

6. UNIX for Dummies Questions & Answers

Find next line based on pattern, if it is similar pattern skip it

Hi, I am able to get next line if it is matching a particular pattern. But i need a way to skip if next line also matches same pattern.. For example: No Records No Records Records found got it Records found Now i want to find 'Records found' after 'No Records' pattern matches.. ... (5 Replies)
Discussion started by: nagpa531
5 Replies

7. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

8. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

9. UNIX for Advanced & Expert Users

I am trying to find pattern between two words but unable to get that pattern..

HI.... It's fallow up file .. #./show.sh click enter button.. i am gettng the fallowup file. its keep on running every time why because there are lots of users working on it. In that file i want to search pattern between two words for ex: SELECT DISTINCT... (7 Replies)
Discussion started by: ksr.test
7 Replies
Login or Register to Ask a Question