[H-GEN] Formatting of ls (grep??)
Anthony Towns
aj at azure.humbug.org.au
Mon Apr 19 03:57:08 EDT 2004
On Mon, Apr 19, 2004 at 04:22:22PM +1000, Mark Suter wrote:
> With this output, a simple sed/perl/whatever script will extract
> that number for you, for example,
> $ find . -type l -printf "%l %f" | sed -e 's/^.*site\([0-9]\).* /\1 /'
> 4 sitedynamics.com.au
> $ find . -type l -printf "%l %f" | perl -lne 'print if s/.*site([0-9]).* (.+)/$1 $2/'
> 4 sitedynamics.com.au
> Although slightly longer, the perl version has the safety feature
> that it will not print anything is the line doesn't match the
> pattern, whereas the sed version will pass it unaltered.
... | sed -ne 's/^.*site\([0-9]\).* /\1 /p'
will do the same. (The -n means don't print lines by default; and the
"p" means print this line if the sed matched)
You probably want to say
-printf "%l %f\n"
to get newlines in the output too. "-maxdepth 1" might be worth looking
into to, if you don't want to look through subdirectories.
find is a cool tool.
Cheers,
aj
--
Anthony Towns <aj at humbug.org.au> <http://azure.humbug.org.au/~aj/>
Don't assume I speak for anyone but myself. GPG signed mail preferred.
Protect Open Source in Australia from over-reaching changes to IP law
http://www.petitiononline.com/auftaip/ & http://www.linux.org.au/fta/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 307 bytes
Desc: Digital signature
URL: <http://lists.humbug.org.au/pipermail/general/attachments/20040419/627eed56/attachment.sig>
More information about the General
mailing list