How to format the output of ls?

bash, linux

Solution

ls -l *.h|awk '/\.h/{print "    "$0" \\"}'

Or in a more simple way in awk:

> ls -1 *.h | awk '$0="    "$0" \\"'

Tested :

> ls -1 *.hh 
Algorithms.hh
Timer.hh
a.hh
> ls -1 *.hh | awk '/\.hh/{print "    "$0" \\"}'
    Algorithms.hh \
    Timer.hh \
    a.hh \
> 

Or you can use perl:

ls -1 *.h | perl -plne '$_="    ".$_." \\";'

Problem

I would like to output all headers in a directory. There is one entry per line and each line should begin with four whitespaces and should end with a whitespace and a '\' character. ``` ____header1.h_\ ____header2.h_\ ____header3.h_\ ``` I already figured out how to make the output one entry per line. ``` ls -1 *.h ``` But I do not know how to do the formatting. Where should I look to learn more complicated formatting? EDIT: All the scripts in all the answers produce the desired output. I wish I could accept all answers.

Original source