Sunday, 26 May 2013

bash: colorize second column of output

bash: colorize second column of output

let's say, I have following output from ls:
$ ls -lAhF /bin
-rwxr-xr-x 1 root root 905K Apr 10  2010 bash*
-rwxr-xr-x 3 root root  31K Dec 26  2011 bunzip2*
-rwxr-xr-x 1 root root 505K Nov 15  2010 busybox*
-rwxr-xr-x 3 root root  31K Dec 26  2011 bzcat*
lrwxrwxrwx 1 root root    6 Jun 24  2012 bzcmp -> bzdiff*
...
I am looking for a way, how I could colorize the second column. I know how to use sed to colorize any pattern, but I don't know how to colorize specific column. Basically, I need to insert '\033[0;31m' after the first space and '\033[0m' infront of the the second space. Or perhaps there is much more elegant way ?

No comments:

Post a Comment