sed expressions
Frank Peters
fwp1 at CC.MsState.Edu
Wed Mar 27 14:20:45 AEST 1991
: On 27 Mar 91 03:29:40 GMT, bguthy at 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 at CC.MsState.Edu Bitnet: FWP1 at MsState
Phone: (601)325-2942 FAX: (601)325-8921
More information about the Comp.unix.questions
mailing list