[H-GEN] Formatting of ls (grep??)
David de Groot
david-humbug at viking.org.au
Sun Apr 18 07:28:54 EDT 2004
On 18/04/2004, at 8:07 PM, Paul Clarke wrote:
> 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.
Try something like this:
Put this into a file called parse.awk:
BEGIN {
FS=" "
}
{
numstr=$11;
name=$9;
i=0;
pos=index(numstr, "site");
pos+=4;
tail=substr(numstr, pos+1);
num=substr(numstr, pos);
printf("%c", num);
while (num ~ /[0-9]+/) {
i++;
num=substr(tail, i, 1);
if (num ~ /[0-9]+/) {
printf("%c", num);
}
}
printf("\t%s\n", name);
}
Then run this:
ls -la | grep "sitedynamics.com.au" | awk -f parse.awk
That'll do it :)
Dave
~yeah it might have been overkill, but it works :)
More information about the General
mailing list