The UNIX and Linux Forums  


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
How to search for capital letters djdaniel3 UNIX for Dummies Questions & Answers 1 04-06-2008 10:05 AM
Search File for Specific Words mevasquez UNIX for Dummies Questions & Answers 2 12-04-2007 04:31 PM
Search files that all contain 4 specific words WoodenSword Shell Programming and Scripting 13 01-22-2007 06:57 AM
how to find capital letter names in a file without finding words at start of sentence kev269 Shell Programming and Scripting 1 04-10-2006 10:35 PM
search for words in file Agent_Orange Shell Programming and Scripting 4 10-25-2002 06:29 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 04-05-2008
djdaniel3 djdaniel3 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
Smile search for words with capital leters

Hi,

I just want to search a file for any words containng a capital letter and then display these words only as a list

I have been trying grep but to no has not helped.(im using the bash shell)
  #2 (permalink)  
Old 04-05-2008
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
Not that I can help with bash but it helps to post the code you have written so far, it may need just a small tweak to work (or may be completely wrong).
  #3 (permalink)  
Old 04-05-2008
ohagar ohagar is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 16
# cat capitals.txt
The quick Brown fox
jumped Over the Lazy Dog

# for i in `cat capitals.txt`
>do
>echo $i | grep [A-Z]
>done
The
Brown
Over
Lazy
Dog


HTH
  #4 (permalink)  
Old 04-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
I still get the creeps when I see "for f in `cat file`", but let's not dwell on that.

You might also want to explore whether your grep has an -o option.


Code:
grep -o '[^ ]*[A-Z][^ ]*' capitals.txt

  #5 (permalink)  
Old 04-06-2008
djdaniel3 djdaniel3 is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 3
Thanks so much code worked Great!
grep -o '[^ ]*[A-Z][^ ]*'

if you could explain it to me that would be great

i had tried grep -o [A-Z] but was not working
  #6 (permalink)  
Old 04-06-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
[^ ] means any character which is not whitespace, and * means zero to infinity of those (remember regular expressions are usually greedy, so it will match as many as it can). If you grep for just [A-Z] then it will only print the actual uppercase characters; extending the regular expression to cover any adjacent non-whitespace characters on both sides should get what you were looking for.
  #7 (permalink)  
Old 04-06-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555
just another way

Code:
awk '
{
  for(i=1;i<=NF;i++) {
   if( $i ~ /[A-Z]/) {
    print $i
   }
  }
}
' file

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 12:27 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