Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!agate!ucbvax!hplabs!hpl-opus!steinbac From: steinbac@hpl-opus.hpl.hp.com (Guenter Steinbach) Newsgroups: comp.unix.questions Subject: Re: Sed question Message-ID: <63720026@hpl-opus.hpl.hp.com> Date: 29 Nov 90 18:30:24 GMT References: <3637@exodus.Eng.Sun.COM> Organization: HP Labs, High Speed Electronics Dept., Palo Alto, CA Lines: 37 In comp.unix.questions, bm@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@hplabs.hp.com