[ale] Need help with RE in egrep

Jim Kinney jim.kinney at gmail.com
Sun Sep 19 18:09:10 EDT 2010


[root at blindtoadstout jkinney]# find / -maxdepth 2 |head -n10
/
/.smolt
/.smolt/uuiddb.cfg
/sys
/sys/fs
/sys/devices
/sys/dev
/sys/bus
/sys/class
/sys/firmware
[root at blindtoadstout jkinney]# find / -maxdepth 2 |head -n10 | sed
's|^/.\+/|/|'
/
/.smolt
/uuiddb.cfg
/sys
/fs
/devices
/dev
/bus
/class
/firmware


OK. So the sed regex need a tweak to dump leading paths that begin with a
'.'

[root at blindtoadstout jkinney]# find / -maxdepth 2 |head -n10 | sed
's|^/[.]\?\.*.\+/|/|'
/
/.smolt
/uuiddb.cfg
/sys
/fs
/devices
/dev
/bus
/class
/firmware


Better. But it still doesn't just dump lines that are only one directory
deep like /sys and /.smolt

That has me stumped. Seems like a alternation expression like

find / -maxdepth 2 |head -n10 | sed 's:^/[.]\?\.*.\+(/|\$):/:'
should work by matching on either a / or a line ending which would render a
top level dir to appear as just /, but it fails to do as expected.

On Sun, Sep 19, 2010 at 3:46 PM, Richard Bronosky <Richard at bronosky.com>wrote:

> Could someone please give me a transcript proof of this in action?
> (complete with mkdir /tmp/sample and touch ...) I really want to
> understand how that could possibly work. Each week I spend hours on
> irc://chat.freenode.net#bash helping people with this exact kind of
> task. I'm not easily stumped. Especially not by a sed less than 60
> characters.
>
> On 9/19/10, Jim Lynch <ale_nospam at fayettedigital.com> wrote:
> > I did a find . | sed 's!^/.\+/!/!'
> >
> > And it produced the output I was looking for.  I didn't investigate it
> > any further.
> >
> > Thanks,
> > Jim.
> > On 09/18/2010 06:39 PM, Richard Bronosky wrote:
> >> I have no idea how that solves the need you explained. I write sed and
> >> awk everyday. I have no idea how a substitution (the s in that sed
> >> script) could ever work to "generate a list of files in a directory,
> >> excluding the top level hidden directories and files." I can only
> >> imagine doing this with the d command like so:
> >> find . | sed '/^\.\/\./d'
> >>
> >> On Sat, Sep 18, 2010 at 4:32 PM, Jim Lynch
> >> <ale_nospam at fayettedigital.com>  wrote:
> >>
> >>> On 09/18/2010 04:02 PM, Jim Kinney wrote:
> >>>
> >>>> sed 's!^/.\+/!/!'
> >>>>
> >>> That works, thanks.
> >>>
> >>> Jim.
> >>> _______________________________________________
> >>> Ale mailing list
> >>> Ale at ale.org
> >>> http://mail.ale.org/mailman/listinfo/ale
> >>> See JOBS, ANNOUNCE and SCHOOLS lists at
> >>> http://mail.ale.org/mailman/listinfo
> >>>
> >>>
> >>
> >>
> >>
> >
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://mail.ale.org/mailman/listinfo/ale
> > See JOBS, ANNOUNCE and SCHOOLS lists at
> > http://mail.ale.org/mailman/listinfo
> >
>
> --
> Sent from my mobile device
>
> .!# RichardBronosky #!.
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>



-- 
-- 
James P. Kinney III
I would rather stumble along in freedom than walk effortlessly in chains.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20100919/5e637907/attachment.html 


More information about the Ale mailing list