[H-GEN] Formatting of ls (grep??)
Mark Suter
suter at zwitterion.humbug.org.au
Mon Apr 19 02:22:22 EDT 2004
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Paul,
> The entries from the la -la that I want to display all have the name in
> the format of a domain and basically look like:
>
> lrwxrwxrwx 1 root root 23 Jul 10 2003 sitedynamics.com.au -> home/virtual/site4/fst
>
> Ideally I want to display just these lines as:
> 4 sitedynamics.com.au
>
> So that the user then inputs 4 if that is the site that they want. The 4
> comes from the siteX in the path.
Perhaps another tool besides ls(1) should be used? I'd suggest
find(1) used in the following manner.
$ find . -type l -printf "%l %f"
home/virtual/site4/fst sitedynamics.com.au
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.
Yours sincerely,
- -- Mark John Suter | I know that you believe you understand
suter at humbug.org.au | what you think I said, but I am not sure
gpg key id 2C71D63D | you realise that what you heard is not
mobile 0411 262 316 | what I meant. Robert J. McCloskey
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Check Keyservers or http://zwitterion.org/keys/
iD8DBQFAg3AeRYso2ixx1j0RAkosAJ9F7COB9fK68zfxMYyp1RknOrXdNACdFDeI
vmZLhBOZJ7VIDw7DgX+M3GA=
=HXVx
-----END PGP SIGNATURE-----
More information about the General
mailing list