Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

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
Marcin Golembski_1
Honored Contributor
Solution

Re: Quick grep format question

You can't do this with grep. If you have perl, try creating a script, say script.pl, containing:

while(<>) {
chomp;
foreach $word (split) {
if ($word=~/^[A-Z]+/) { print $word,"\n"; }
}
}

then run it:

perl script.pl yourfile > resultfile

resultfile will contain all words from yourfile starting with an uppercase letter, one word per line. If you want only all-uppercase words, add $ after + and if you want uppercase anywhere in the word, remove ^.

HTH,
Marcin
Volker Borowski
Honored Contributor

Re: Quick grep format question

Hi,
here a solution without perl:

# cat bastel.sh
action()
{
while [ $# -gt 0 ]
do
echo $1 | grep -e '[A-Z]'
shift
done
}

while read LINE
do
action $LINE
done
#

Volker
eugene_6
Advisor

Re: Quick grep format question

echo inputfile | awk 'BEGIN { RS="[\ \t]"} { print $1 }' | grep [A-Z] > outputfile
eugene_6
Advisor

Re: Quick grep format question

short correction
---------------------------

echo inputfile | awk 'BEGIN { RS="[\ \t]"} { print $1 }' | grep ^[A-Z] > outputfile