Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!emory!ra!Ra.MsState.Edu!fwp1 From: fwp1@CC.MsState.Edu (Frank Peters) Newsgroups: comp.unix.questions Subject: Re: sed expressions Message-ID: Date: 27 Mar 91 04:20:45 GMT References: <1991Mar27.032940.10026@terminator.cc.umich.edu> Sender: usenet@ra.MsState.Edu Followup-To: comp.unix.questions Distribution: usa Organization: Computing Center, Mississippi State University Lines: 35 Nntp-Posting-Host: jester.cc.msstate.edu In-reply-to: bguthy@engin.umich.edu's message of 27 Mar 91 03:29:40 GMT : On 27 Mar 91 03:29:40 GMT, bguthy@engin.umich.edu (bala s guthy ) said: > % ls -l | sed 's/[1-9].* //' > % drwx------ xy1991 The [1-9] matches any digit between one and nine. This anchors beginning of the pattern at the link count field since that is the first digit in a ls -l line. The .* matches 0 or more occurences of any character. This would ordinarily remove everything up until the end of the line. But you tossed a space in there. This means that the pattern will end with a space. Now, here is where I expect that you're being confused. The pattern matching takes up as much of the line as it can rather than as little. In other words, it doesn't stop the first time it matches the pattern on a line. Rather, it continues parsing to see if it can find another match using more of the line. The effect of this is that your pattern stops on the LAST space in the line instead of the first as I think you expected. Since the last space is usually the one before the file name (doesn't have to be...I have several files with spaces in their names) that is where the pattern ends and is thus what is removed. Please let me know if this doesn't make any sense. I keep thinking I should be able to explain it more clearly. Regards, Fwp -- Frank Peters Internet: fwp1@CC.MsState.Edu Bitnet: FWP1@MsState Phone: (601)325-2942 FAX: (601)325-8921