[lug-nuts] one liner

From: Sean-Paul Rees (sean@dreamfire.net)
Date: Sat Dec 18 1999 - 13:31:27 PST


Background:
        I like listing files in directories. Sometimes I just want to list the
directory names. Instead of sifting through the manpage for ls, I
decided to put some brain power to it and make a quick little one-liner.
I'm learning how to program in awk, so I made the a quick little awk
script to convert the output into a nice comma'ed list.

Prerequisites:
        ls aliased to -F (or add it to the command line)
        grep
        awk

Cheap Solution:
        Quicky: ls [-F] | grep "/"$ | more
        Lots of info: ls -la[F] | grep "/"$ | more

        A comma'ed
list: !
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               !
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               !
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               !
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               !
             
        
        ls [-F] /etc | grep "/"$ | awk -f etc.list.awk

        begin etc.list.awk:
                # awk will turn this list into a comma'ed list
                { line[NR] = $0 } # remember each input line
                END { for (i = 1; i <= NR; i = i + 1) # Spit it out again
                        if ($i == NR)
                                printf("%s\n", line[i])
                        else
                                printf("%s, ", line[i])
                }
        end etc.list.awk

Description:
        ls -F lists the files with characteristics, for instance a trailing "/"
for directories.
        
        grep "/"$ selects the entries with the trailing / and only the trailing
/.

        more makes a list.

Cheers,
Sean
****************************************************************************
* To UNSUBSCRIBE from the list, send a message with "unsubscribe lug-nuts"
* in the message body to majordomo@saclug.org. Please direct other
* questions, comments, or problems to lug-nuts-owner@saclug.org.



This archive was generated by hypermail 2b29 : Fri Feb 25 2000 - 14:29:09 PST