I am trying to list all the files in the directory but how would you separate each of the files by a blank line? basically each file displayed by separated by a blank line? I am trying to use a for loop? I did try few examples but none really work by spacing a blank lines in between?
for i in ls
do
echo "\n" && ls -l
done
for i in ls
do
echo "\n"
ls
done
For reference : http://www.cyberciti.biz/faq/bash-loop-over-file/
Edited as per comments making it simpler.
sed
one-liner (or one-char-er):Done.
Here's one:
A slightly worse (but more portable) one:
A more convoluted one:
And here is what you should not ever do:
EDIT:
And, as mentioned by Nija, the simple shell-only one:
This one has the disadvantage that on many shells
*
by default expands to itself, rather than an empty string when no files exist.Your loops are close. However, using a traditional bash
for
loop withls
is dangerous - what happens if your filenames contain spaces? An easy solution withawk
:Not sure how portable the options -d and -t are, but pr is ubiquitous:
Note that any file names with an embedded carriage return will have an extra carriage return added in the output. (I believe that problem occurs with all of the solutions presented so far.)