On 18 Feb 20:39, Chris Green wrote:
On Tue, Feb 18, 2014 at 06:38:42PM +0000, Chris Walker wrote:
On Tue, 18 Feb 2014 18:28:43 +0000 Chris Green cl@isbd.net wrote:
I think I'd do something like the following, on the command line with no scripts:-
for fn in *.vcf do cat "$fn" >>listfile echo >>listfile echo >>listfile done
You can type it just as I have listed it above as the shell will prompt for the intermediate lines with a '>' until you enter the line with 'done'.
OK. I've followed your instructions and I do indeed end up with a listfile comprising all the vcf entries.
But I don't understand why it works so can you explain it for me please? The problem I have is why am I running the echo line twice?
The 'for' executes everything between the 'do' and the 'done' for each .vcf file. The 'cat' does what you know, I put quotes round the file name to make it work with filenames that have embedded spaces. 'echo' just outputs what's after it, which in the above case is nothing except for CR/LF (end of line). I just did two echoes to give you two blank lines.
ENOTTRUE, echo, by default, won't do CR/LF, just LF. About the only place that a CR/LF pair is still used is in DOS format text files.
If you'd wanted a CR/LF pair, you could use:
echo -ne '\r\n\r\n'
Which would be 2 new lines in DOS text file format.
If you just wanted 2 new lines, you could just use:
echo -ne '\n\n'
Also, the for loop has the issue that if *.vcf expands too much (i.e. if there's lots and lots of files in the list), then it'll also fail.
So, really, it should have gone something like...
find . -maxdepth 1 -name *.vcf -print0 | while read -d $'\0' -r file; do (cat "$file" && echo -ne '\n\n') >> all.out; done
Which deals with interesting filenames, only uses 1 redirection, and should be marginally quicker.
Thanks,