LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-13-2007, 04:00 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676
Blog Entries: 7

Rep: Reputation: 32
REGEXP Match * through multiple lines ?


Hi All
I am learning about regexp right now, I read at
http://www.regular-expressions.info/dot.html the following

The dot matches a single character, without caring what that character is. The only exception are newline characters. In all regex flavors discussed in this tutorial, the dot will not match a newline character by default. So by default, the dot is short for the negated character class [^\n] (UNIX regex flavors) or [^\r\n] (Windows regex flavors).

The question is how to match any character through multiple lines. I.e. START..multiple lines .* END

Thx for any help
 
Old 08-13-2007, 07:56 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Wherever you use
Code:
.
replace it with
Code:
[.\n]
Hope this helps.
 
Old 08-13-2007, 08:06 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
It doesn't work. [.] is simply dot. I'd bet on
Code:
(.|[\n])
It works in Vim (in verymagic mode, you'll need
Code:
\(.\|[\n]\)
usually). But in Vim you can just use
Code:
\_.
.
 
Old 08-13-2007, 08:07 AM   #4
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
To: wjevans_7d1@yahoo.co
The thing is that the search words are not located at the beginning of the line..so it does not work..I need to match at any location not just at the start of the line...I mean that is how I understood .\n
I tried it ..it did not work
Thx for the help so far any more suggestions ?

I will try raskin's suggestion now
 
Old 08-13-2007, 08:11 AM   #5
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
[root@localhost logs]# cat call.log | sed -n -e '/IN.|[\n]From: 9613041705 <sip/','/Contact: "9613041705"/p'

Did not return any results.

AAA = IN
BBB = From: 9613041705 <sip
CCC = Contact: "9613041705

I need to get the text from AAA to CCC with BBB included , the text spawns over multiple lines..and the location of the words differs.
Any suggestions please..
 
Old 08-13-2007, 08:24 AM   #6
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
[root@localhost logs]# cat call.log | sed -n -e '/IN(.*|.\n)From: 9613041705 <sip/','/Contact: "9613041705"/p'

This did not work either.
 
Old 08-13-2007, 08:31 AM   #7
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Sed doesn't play nice with newlines anyway. If you find how to convert all newlines with to pluses, I will modify it to do what you want from it now.. But I think it will not wok well.
 
Old 08-13-2007, 10:32 AM   #8
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
Thank you that would be great...can u suggest any other way to do it if sed does not play along well
 
Old 08-13-2007, 10:49 AM   #9
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Maybe something like this?
Code:
sed -ne '/AAA/,/CCC/p' filename
 
Old 08-13-2007, 10:54 AM   #10
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
sed and awk won't do that. perl and php can though

Yves.
 
Old 08-13-2007, 11:01 AM   #11
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Seems like I'm the only one who doesn't understand the question...
 
Old 08-14-2007, 01:51 AM   #12
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676

Original Poster
Blog Entries: 7

Rep: Reputation: 32
Dear spirit receiver your code does work well however it does not take into account that BBB must be found in between those two entities..I.e. it matches

AAA-----no BBB------>CCC Wrong
&&
AAA------BBB-------->CCC Right..

Can you help me to adjust the code accordingly ?
Thx
 
Old 08-14-2007, 07:39 AM   #13
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
This might work (but probably not with all flavors of sed):
Code:
sed -ne '/AAA/{:LOOP /CCC/{b CHECK};N;b LOOP;:CHECK /BBB/p}' filename
When /AAA/ matches, all lines until /CCC/ are added to the pattern space. Then the pattern space is checked for /BBB/.

Last edited by spirit receiver; 08-14-2007 at 07:42 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
AWK/SED Multiple pattern matching over multiple lines issue GigerMalmensteen Programming 15 12-03-2006 05:08 PM
Using diff and erasing the lines that match ElectroLinux Linux - Newbie 4 09-20-2006 03:34 AM
ISDN multiple lines schimmelpilz Linux - Newbie 1 02-24-2004 05:39 PM
combining multiple dsl lines BaudRacer General 3 01-12-2004 09:15 AM
Multiple redundant WAN lines. hubergeek Linux - Networking 8 07-25-2003 09:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration