LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2014, 06:56 PM   #1
bandito40
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Rep: Reputation: 0
grep - dealing with EOL


I am attempting to search through several lines of text with the following reg expression using grep:

Code:
grep -o '9[0-9] [8-9][0-9] 9[0-9].*\{40\}' sample.txt
Works but grep does not always return the following 40 characters. Instead it only returns up to 40 characters to the EOL which ever comes first.

What I am looking to do is get the following 40 characters whether there is an EOL within the following 40 characters or not.

Rather not show with what I have in sample.txt but here is the idea:

sample.txt
Code:
90 80 90 hello there
good bye
returns....

Code:
90 80 90 hello there good
 
Old 05-13-2014, 10:38 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Well I am not sure I understand how that regex works at all? After the number section you say, return zero or more of any character and then you want 40 lots of the previous expression???

As to answer your question, if newlines are allowed in the solution then you will probably need to include them in your regex.
 
Old 05-13-2014, 01:02 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,784

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Native grep works on single lines and cannot do multi-line matches. There is a somewhat experimental "-P" option to use Perl regular expressions, which would support that. Here is a link to a discussion with an example of multi-line matches using "grep -P".
 
Old 05-15-2014, 09:07 AM   #4
bandito40
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
-a1 did the job. Thanks for your help
 
Old 05-15-2014, 09:44 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
And if the 40 characters were to go over more than 1 extra line? How will you know to make -A2 or more?
 
Old 05-16-2014, 06:45 AM   #6
bandito40
LQ Newbie
 
Registered: Jan 2010
Posts: 7

Original Poster
Rep: Reputation: 0
In this situation that would not be the case.
 
Old 05-16-2014, 07:24 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Well if happy with your solution, please mark the question as SOLVED
 
  


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
Ubuntu 11.04 EOL robsbots Linux - Server 3 09-14-2013 08:31 AM
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
Fedora 12 EOL Skaperen Fedora 8 12-03-2010 08:09 AM
EOL Slackware-10.1 thenob Slackware 2 04-02-2010 02:07 AM
IBM p-series EOL list. xhlseet AIX 1 07-16-2009 10:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:28 AM.

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