Go Back   The UNIX and Linux Forums > Top Forums > Homework & Coursework Questions
Search Forums:



Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-09-2012
Registered User
 

Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Regular Expressions with GREP

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Given a text file (big_english.txt) containing roughly 250,000 words, answer the following using grep and regular expressions:

16. For which words are the first three letters the same as the reverse of those letters at the end?

17. What is the longest palindrome in this dictionary?

2. Relevant commands, code, scripts, algorithms:

n/a


3. The attempts at a solution (include all code and scripts):

(What I've got on 16... comes up null, but the question to 17 implies that there should be at least a few hits)

grep -i '^\(\w\)\(\w\)\(\w\)\w\*/\3/\2/\1$' big_english.txt


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University of Nebraska at Omaha
Omaha, NE, USA
Dr. Mark Pauley
Advanced Bioinformatics Programming (BIOI 3500)
Sponsored Links
    #2  
Old 02-09-2012
itkamaraj's Avatar
Unix is God
 

Join Date: Apr 2010
Posts: 2,330
Thanks: 21
Thanked 466 Times in 455 Posts
regex for palindrome. Read and understand

regex - How to check that a string is a palindrome using regular expressions? - Stack Overflow
Sponsored Links
    #3  
Old 02-13-2012
Registered User
 

Join Date: Feb 2012
Location: Mumbai
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
16 ) you hit null results since you have explicitly escaped the *. It makes the grep command to look for actual 'asterix' in the words.

instead of ::
grep -i '^\(\w\)\(\w\)\(\w\)\w\*/\3/\2/\1$' big_english.txt

make it::

Code:
grep -i '^\(\w\)\(\w\)\(\w\)\w*\3\2\1$' big_english.txt

This will return you the list of words having the first three letters repeated in the last three positions with in reverse order with zero or more characters in between.

Last edited by george88; 02-13-2012 at 12:47 PM..
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
extract columns using grep or regular expressions quextil UNIX for Dummies Questions & Answers 3 01-19-2012 12:17 PM
How to grep using a line break in regular expressions? divak Shell Programming and Scripting 5 12-10-2009 12:57 AM
searching regular expressions with special characters like dot using grep jpriyank Shell Programming and Scripting 4 08-12-2009 03:04 AM
grep and regular expressions : Browser_ice UNIX for Dummies Questions & Answers 2 08-15-2006 02:10 AM
More Grep - Regular Expressions Jombee UNIX for Dummies Questions & Answers 7 09-05-2005 12:55 PM



All times are GMT -4. The time now is 11:21 PM.