0
votes
ls -lhAXF --group-directories-first "$@" | awk '
    BEGIN {
        FPAT = "([[:space:]]*[^[:space:]]+)";
    } {
        $1 = "\033[1m" "\033[31m" $1 "\033[0m";
        $2 = "\033[1m" "\033[32m" $2 "\033[0m";
        $3 = "\033[1m" "\033[33m" $3 "\033[0m";
        $4 = "\033[34m" $4 "\033[0m";
        $5 = "\033[1m" "\033[35m" $5 "\033[0m";
        $6 = "\033[1m" "\033[36m" $6 "\033[0m";
        $7 = "\033[1m" "\033[37m" $7 "\033[0m";
        $8 = "\033[1m" "\033[33m" $8 "\033[0m";
        print
    }'

link to the output

what is the correct syntax to achieve the following:

  1. color normal directory to red
  2. color hidden directory to blue
  3. color regular file to green

what i know:

  1. match normal directory with regex like any word ending with '/' inside column $9
  2. match hidden directory with regex like any word starting with '.' inside column $9
  3. match regular file with regex like the rest of line that doesn't match ending with '/' and doesn't match starting with '.'
  4. i know something like: awk '$9 ~ /something/' to match the right column

but where to put the syntax, and what is the syntax look like?

i want to colorize the result of the regex after it matches using escape code like "\033[32m"

Your question is not clear. You write that you want to "colour normal directory to red" but you show an awk script and an image where it is the various columns that are coloured, note the lines. So, for "normal directories", for instance, what information do you want to be printed in red? Its name? The permissions? Other? And what about the other colours?Renaud Pacalet