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)

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).

# 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

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.

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

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

[^ ] 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.

just another way

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