grep, egrep, and regular / extended regular expressions [Help!] - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Linux and Open Source
Click Here to Login
Closed Thread
 
Thread Tools Display Modes
 
Old 10-12-2011, 10:41 AM   #1 (permalink)
 
iFargle's Avatar
 
Join Date: Jan 2009
Location: N/A
Posts: 4,354
Default grep, egrep, and regular / extended regular expressions [Help!]

I am lost as to how to do this.. I understand basic regular expression syntax, but I can't seem to wrap my head around this one.

This is a homework assignment.. Just to clarify. I've looked everywhere but can't find an answer

The question:

Using grep -E on the above file, display the number of students who received a lab grade of 5 six times consecutively.

The file:

0673 4 5 5 5 5 5 5 5 5 4 67 80 83
0788 5 5 5 5 5 5 5 5 5 5 100 87 105
0821 5 5 5 5 5 5 5 5 5 5 93 80 88
1641 5 5 5 4 5 5 5 0 5 4 87 47 94

My answer:

So far really none... This is what I think it should be, but I'm obviously wrong
grep -E '(5\s)\{6,\}' file
I can get it to display consecutive fives with grep, not egrep (and only fives, not the spaces before or after it):
grep '5\{6,\}' file
But now I'm stuck. I know with extended regular expressions the parentheses group patterns together and the \{\} indicates how many times a character occurs before it is listed, but I can't seem to find what I need to: a 5 and a space consecutively.

Unless I'm going about this in a totally wrong direction...
let me know if that's the case

Thanks for any help
__________________

__________________

- iFargle.com -
Desktop || 7700k 32GB RAM 2TB M.2 SATA GTX 1080 DAN A4v4 Fedora 31 WS
Laptop || Lenovo X1 Carbon 16GB RAM 512GB SSD Intel UHD 620 Fedora 31 WS
OnePlus 6 LineageOS 16 64GB iPad Air 2 || Battle.net: iFargle #1561 Steam: iFargle
iFargle is offline  
Old 10-12-2011, 02:54 PM   #2 (permalink)
Newb Techie
 
Join Date: Oct 2011
Location: East Coast
Posts: 5
Default Re: grep, egrep, and regular / extended regular expressions [Help!]

grep -E '(5\s)\{6,}\' file


You are so close with this expression. there's only 3 unneeded characters. 2 are the same.
Remember, {} is a sequence, so you should only need {6}.
That's all I can say w/o giving you the answer. (Although, some could argue I already have).
__________________

__________________
mithryn is offline  
Old 10-12-2011, 05:06 PM   #3 (permalink)
 
iFargle's Avatar
 
Join Date: Jan 2009
Location: N/A
Posts: 4,354
Default Re: grep, egrep, and regular / extended regular expressions [Help!]

omg I just realized what I was doing wrong.. It isn't a single space, it's two spaces. :anger:
Also.. I thought that was only with certain commands. Glad to know that works with grep

Thank you for your help

For those wondering.. my final answer:

grep -E '(5 ){6,}' file
If you can't see the second space...
grep -E '(5<space><space>){6,}' file
__________________

- iFargle.com -
Desktop || 7700k 32GB RAM 2TB M.2 SATA GTX 1080 DAN A4v4 Fedora 31 WS
Laptop || Lenovo X1 Carbon 16GB RAM 512GB SSD Intel UHD 620 Fedora 31 WS
OnePlus 6 LineageOS 16 64GB iPad Air 2 || Battle.net: iFargle #1561 Steam: iFargle
iFargle is offline  
Closed Thread

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to have a laptop that reads regular CDs and burns/plays regular DVDs? time29 Laptops and Notebooks 4 12-30-2010 09:19 PM
USB or Regular IDE SpikedCola System Upgrades 4 08-27-2006 07:33 AM
Opterons for regular PC? PixelManual System Upgrades 3 02-12-2006 05:54 AM
grep & egrep rookie1010 Linux and Open Source 0 05-31-2004 08:07 AM



All times are GMT -5. The time now is 10:30 AM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2020, vBulletin Solutions, Inc.