On Tue, 18 Feb 2014 18:28:43 +0000 Chris Green cl@isbd.net wrote:
On Tue, Feb 18, 2014 at 06:11:34PM +0000, Chris Walker wrote:
I've been trying for over an hour to concatenate a load of .vcf files for import into another device.
I need to have a carriage return and line feed between each vcf so I created a spacerfile which contained just those two characters.
I then generated a list of all the files with the ls command. I then used that file like this :- while read file ; do cat $file spacerfile.txt >> all_in_one.vcf ; done <listfile.txt
But all I get is a load of blank lines with just one or two vcards inserted and then a long list of the vcf files which is most of the listfile.txt.
I am also seeing this type of error :- cat: First: No such file or directory cat: Name.vcf: No such file or directory
That made me wonder if it was because there are spaces in the file names and hence in the listfile.txt so I amended the text file so that each space was preceded by the escape character. But it still doesn't work.
From the error messages you're seeing I think "because there are spaces in the file names" is exactly your problem.
I don't think I'd do it quite the way you have, spaces in filenames in a shell script are always very painful to handle.
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?
Ta.