[Tutor] concatenating files

Alan Gauld alan.gauld at btinternet.com
Sat Feb 28 01:52:44 CET 2009


"Bala subramanian" <bala.biophysics at gmail.com> wrote

> I have file1.dat,file2.dat...file 300.dat  in one directory. I want 
> to
> concatenate all the files in a single file  (total.dat) with a 
> string "END"
> separating the file contents.

If you are on Linux (or other *nix variant) you may be better off
using the shell...

for f in *.dat
do
cat $f >> total.dat
echo "END" >> total.dat
done

Will do it for you.
If you are on Windoze then you need to write a batch file and
then execute it within the for loop so I'd just stick with Python
there.  (Or install cygwin :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list