merging multiple timestamps into one

Here is a problem that involves looping:

  • I have multiple files with same name but different timestamps:
    e.g test20080226144525.txt, test20080227144525.txt (can be more
    than two files).
  • I want to take the collection of these files (e.g test*) and append all its contents to one file.
  • This new file with appended contents will be named
    test226144525_20080227144525.txt (concatenate timestamps to the filename).

Thanks,

CB

I see one problem at least. There are limits to filename length on a lot of unix filesystems.
If you have more than two files, you could start getting in trouble. Some filesystems may be okay. I dunno what filesystems you have.

That said, try something this ksh script:

#!/bin/ksh
set -A arr test*
cat ${arr[*]} > tmpfile
newname="test"
for i in test*
do
     t1=${i#test}
     t2=${t1%.txt}
     newname=$newname"_$t2"
done
newname=$newname".txt"
mv tmpfile $newname

Hi,

I think you can cut the changing part of the names with "cut -c"
then use "xargs" with "echo" to obtain single line and then "tr -d" to remove spaces.

But consider that with names like you presented you can easily generate too long filename.

Regards,