Operating System - HP-UX
1834752 Members
2787 Online
110070 Solutions
New Discussion

Quick grep format question

 
SOLVED
Go to solution

Quick grep format question

All - I need some help.

I want to use grep to copy all the words in a file which have uppercase letters into another file.

I just want the uppercase words themselves, not the entire line.

Can someone give me the command?

I'd appreciate it.

Thanks !
"...it's turtles all the way down."
4 REPLIES 4
Robin Wakefield
Honored Contributor
Solution

Re: Quick grep format question

Hi Pamela,

If you want each word on a separate line:

for word in `cat {filename}`;do
echo $word | grep [A-Z]
done

Rgds, Robin.
Andreas Voss
Honored Contributor

Re: Quick grep format question

Hi,

here a little correction:

for word in `cat `
do
echo $word | grep '[[:upper:]]'
done > newfile

Regards
James R. Ferguson
Acclaimed Contributor

Re: Quick grep format question

Hi Pamela:

I'll add one new twist, too. I'm going to assume words might have upper and lower case letters just like in a sentence. I will assume too that you want only those words where ALL letters appear in uppercase and that they may appear with a trailing comma or period. Thus:

for WORD in `cat myfile`
do
echo $WORD||grep '^[A-Z,.]*$'
done > mynewfile

Regards!

...JRF...


Re: Quick grep format question

Thank You Everyone !

You've all come through for me like gangbusters.

Best Regards,
Pamela Goodwin
"...it's turtles all the way down."