Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-01-2010, 08:55 AM   #1
Registered: Nov 2010
Location: Milan, Italy
Distribution: Linux Mint 13, Debian 6.0
Posts: 62

Rep: Reputation: 3
Question Having trouble with grep command

I'm trying to use grep to find the words in the dictionary that contain the letters "th" and the letter m.

I tried

grep 'th m*.' Desktop/Dictionary/words(Thats where the destined dictionary word document is located)

grep 'th' Desktop/Dictionary/words works but only for the words with th. I have no idea of what expression to use to make it a unionized expression with m
Old 12-01-2010, 09:13 AM   #2
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614Reputation: 614

m and th, in any order? Try "(th.*m|m.*th)". You'll need to use grep's -E switch to turn on extended regexes (or -P for PCRE).
1 members found this post helpful.
Old 12-01-2010, 09:27 AM   #3
LQ Newbie
Registered: Jan 2010
Location: Belgium
Distribution: Debian
Posts: 17

Rep: Reputation: 0
I was going to suggest

grep -E '.*(th|m).*(th|m).*' Desktop/Dictionary/Words

but AlucardZero's suggestion works fine.

The site he suggested is a really great source of information on regular expressions as well.
Old 12-01-2010, 05:04 PM   #4
Registered: Nov 2010
Location: Milan, Italy
Distribution: Linux Mint 13, Debian 6.0
Posts: 62

Original Poster
Rep: Reputation: 3
thank so much you were a great help and thanks for the website, i have bookmarked it because it contains a lot of vital information


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trouble with grep extended regez in for loop ineluki12 Linux - General 3 06-03-2010 04:58 PM
How to pass the result of a command to another command (like grep) desb01 Programming 4 06-25-2009 01:09 PM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 05:16 AM
trouble with grep command thodo Programming 3 08-19-2007 08:46 AM
cat [file] | grep --- trouble bob_man_uk Linux - General 12 03-10-2006 07:05 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:26 AM.

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