The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Grep help flood Shell Programming and Scripting 3 06-06-2008 01:14 AM
Grep Aejaz UNIX for Advanced & Expert Users 3 04-30-2008 07:10 AM
grep dineshr85 Shell Programming and Scripting 1 10-10-2007 04:52 AM
how to exclude the GREP command from GREP yamsin789 UNIX for Advanced & Expert Users 2 10-05-2007 02:59 AM
Make grep -c display like grep -n? Jerrad Shell Programming and Scripting 2 08-25-2006 12:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-30-2006
Poison Ivy Poison Ivy is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 25
Question using Grep

I'm trying to figure out what command I would enter in to get all 4 letter words (only a-z characters, punctuations should not be counted as a letter)

I have this so far:
Code:
cat /usr/share/dict/words | egrep '^....$'
But that command counts punctuations such as ' as letters
  #2 (permalink)  
Old 07-30-2006
xinusys xinusys is offline
Registered User
  
 

Join Date: May 2006
Posts: 13
Smile Hi!

use regular expression man.it's very easy.
  #3 (permalink)  
Old 07-30-2006
Poison Ivy Poison Ivy is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 25
umm sorry i dont know what u mean lol im very new to unix
  #4 (permalink)  
Old 07-30-2006
nathan nathan is offline VIP Member  
Supporter
  
 

Join Date: Jul 2006
Posts: 156
A google search for "regular expressions" will give you all the information you need to know. Please note - they're not just Unix-specific.

Code:
$ cat /usr/share/dict/words | egrep '^[a-z]{4}$' | head -3
aahs
aals
abac
  #5 (permalink)  
Old 07-30-2006
Poison Ivy Poison Ivy is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 25
that's good actually but what i meant was to include words such as she's as 4 letter word etc..
  #6 (permalink)  
Old 07-31-2006
nathan nathan is offline VIP Member  
Supporter
  
 

Join Date: Jul 2006
Posts: 156
Use a regular expression to match the pattern:

letter + [not a letter] 0 or more times +
letter + [not a letter] 0 or more times +
letter + [not a letter] 0 or more times +
letter + [not a letter] 0 or more times

It's quite easy, I used it to find these words that start with "she" in my /usr/share/dict/words file.


shea
she'd
shed
shee
shem
sher
shes
shew
  #7 (permalink)  
Old 07-31-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Code:
grep -wE  "[[:lower:]]{3}[[:punct:]]{0,}[[:lower:]]{1}"
3 letter combination + any number of punctuation marks + 1 letter
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On




All times are GMT -4. The time now is 03:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0