Sed question

Guenter Steinbach steinbac at hpl-opus.hpl.hp.com
Fri Nov 30 05:30:24 AEST 1990


In comp.unix.questions, bm at bike2work.Eng.Sun.COM (Bill Michel) writes:

> All I want to do is match the first word (all caps) on each line.
> My input looks like

>  Shortname            
>  --------------------
>  IPCINSTALL         
>  DESKSET           
>  SS2INSTALL       

> and I'm trying sed -n '/^ *[A-Z0-9]*/p' without success (the output is 
> exactly the same as the input). 

That is because * matches 0 or more occurrences.  So you are in effect
asking for "first 0 or more blanks, then 0 or more capital letters" -
that is all lines, regardless of content, since you don't specify what
comes after those two.

Try this:
sed -n '/^ *[A-Z0-9][A-Z0-9]* *$/p'
            ^^^^^^^^         ^ ^
At least one capital         | |
latter.                      | |
                             | |
The lines in your posting have |
trailing blanks.  Put the blank|
inside the brackets if you     |
want to match multiple capital |
words.                         |
                               |
This prevents matching lines with anything but capitals, numbers, and
blanks.

Good luck!

	 Guenter Steinbach		gunter_steinbach at hplabs.hp.com



More information about the Comp.unix.questions mailing list