LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-17-2012, 11:32 AM   #1
Micky12345
Member
 
Registered: Feb 2012
Posts: 58

Rep: Reputation: Disabled
grep command for uppercase


i wrote a command
Code:
grep '^[[:upper:]]' file1
I want to find lines of file1 which contains only capital letters , but when i execute above command

i got lines starting with capital letter but after that it may or maynot contain capital letters

contents of my file1 are
Code:
HELLO
hello
Hello
HEllO
HOW
IT shows output as
HELLO
Hello
HEllo
HOW


But its not what i am expecting i want only output as
HELLO
HOW
 
Old 03-17-2012, 11:38 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Your regular expression matches a single character at the beginning of each line. Instead, you need to match any number of upper-case characters till the end of the line (add the $ anchor):
Code:
grep '^[[:upper:]]*$' file1
Edit: the command above matches empty lines, as well. To match only lines containing at least one upper-case character, use the extended regular expression option and the + modifier:
Code:
grep -E '^[[:upper:]]+$' file1

Last edited by colucix; 03-17-2012 at 11:41 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass the result of a command to another command (like grep) desb01 Programming 4 06-25-2009 12:09 PM
Command to list files starting with uppercase letter djfog Linux - Newbie 5 07-04-2008 05:30 AM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 04:16 AM
UPPERCASE to lowercase command? pk21 Linux - General 4 06-12-2007 10:26 AM
how to use grep command sharonyiisl Linux - Newbie 7 05-28-2006 03:46 PM


All times are GMT -5. The time now is 02:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration