Re: sed problem

From: Bruce Zimmer (b.r.zimmer@WORLDNET.ATT.NET)
Date: Fri Jul 19 2002 - 23:01:27 EDT


To be a little more specific the first expression returns any line that
contains the number 9 followed by 0 followed by zero or more occurrences of
the number 0 .

The second expression will return any line that contains zero or more
occurrences of either a 9 or a 0 . If what you want is an expression to
print only lines that contain a 9 or zero use

sed -n -e '/[09].*/p' sample.txt

This will get any line that contains a 9 or zero followed by zero or more
occurrences of any character. Likewise, if you wanted any line that
contained the number 900 you would use

sed -n -e '/900.*/p' sample.txt

Remember that an * is a multiplier for the single character RE immediately
preceding it. ( and yes, I know that it can be a multiplier for a
multi-character RE, but that is another thread...)

Bruce Zimmer
Central Data Systems
bzimmer@centraldata.com

> -----Original Message-----
> From: IBM AIX Discussion List [mailto:aix-l@Princeton.EDU]On Behalf Of
> Adams Kevin J
> Sent: Friday, July 19, 2002 3:53 PM
> To: aix-l@Princeton.EDU
> Subject: Re: sed problem
>
>
> Doesn't * mean zero or more and + means one or more?
>
> Kevin
>
> -----Original Message-----
> From: Y.SINGH@PONL.COM [mailto:Y.SINGH@PONL.COM]
> Sent: Friday, July 19, 2002 1:16 PM
> To: aix-l@Princeton.EDU
> Subject: [aix-l] sed problem
>
>
> Friends , a stupid question.
> Following is the file of 9 lines (sample.txt) :
> 900
> 12356
> 2.1
> 3.14159265
> 87878787
> 0.25
>
>
> a
>
> if i give command ,
> sed -n -e '/900*/p' sample.txt
> I get output of just one line ,
> 900
>
> Now if I give command ,
> sed -n -e '/[09]*/p' sample.txt
> I get all the lines in output ,
> 900
> 12356
> 2.1
> 3.14159265
> 87878787
> 0.25
>
>
> a
>
> Why is that ?? I am expecting combination of only 0 & 9 in output .
> Please advice.
>
>
> -------------------------------------------------------------------
>
> The contents of this e-mail are confidential to the ordinary user
> of the e-mail address to which it was addressed and may also be
> privileged. If you are not the addressee of this e-mail you should
> not copy, forward, disclose or otherwise use it or any part of it
> in any form whatsoever. If you have received this e-mail in error
> please notify us by telephone or e-mail the sender by replying to
> this message, and then delete this e-mail and other copies of it
> from your computer system. Thank you.
>
> We reserve the right to monitor all e-mail communications through
> our network.
>
>
> This electronic message transmission, including any attachments,
> contains information from PacifiCare Health Systems Inc. which
> may be confidential or privileged. The information is intended to
> be for the use of the individual or entity named above. If you
> are not the intended recipient, be aware that any disclosure,
> copying, distribution or use of the contents of this information
> is prohibited.
>
> If you have received this electronic transmission in error,
> please notify the sender immediately by a "reply to sender only"
> message and destroy all electronic and hard copies of the
> communication, including attachments.
>



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:04 EDT