Copying files to directories based on first 6 character

guys, i did create a script but its too long, though it function the same.

[root@log Sophos]# cat nightlyscan.sh
#!/usr/ksh

deyt=`date +"%Y-%m-%d"`

for i in `ls -lrt|grep $deyt|awk '{print $9}'`
do
cp -f $i /S1/Sophos/logger/

done
[root@log Sophos]#

but i did not paste it all.

this is the desired.

if you have 4 directories
DATA11
DATA22
DATA33
DATA43


And you have files like
DATA11.txt
DATA11.tgz
DATA22.xls
DATA33.as


Output
the directory DATA11 shoud have files of DATA11.txt and DATA11.tgz
DATA22 directory should have file of DATA22.xls and so on.

Why didn't you paste it all? If we can't see what you're doing, we're wasting our time trying to improve it.

The code snippet you have shown us seems to be doing something very different from what you said you want this script to do.

Show us what you have done!

#!/usr/ksh

deyt=`date +"%Y-%m-%d"`

for i in `ls -lrt /NAS1/Sophos/  |grep $deyt|awk '{print $9}'`
do
cp -f /NAS1/Sophos/$i /NAS1/Sophos/logger/
done



for dir in `ls -d /NAS1/Sophos/logger/*/ | sed 's/.$//'`
do
rm -f $dir/*.tar
mv -f $dir*tgz* $dir/
gunzip $dir/*.tgz
done



I'm still not sure what you request, and I still don't see any difficulties/problems in the snippets provided. If shoving files into aadequate directory is what you want, try e.g.

for FN in DATA* ; do mkdir -p ${FN%.*};  mv $FN ${FN%.*}; done

ill try that on monday.. but i can gunzip files,based onmy directorues.. but i cant tar....any idea?

i cant tar xvf

I'm lost. I don't see any reference to tar xvf in this thread other than you saying you can't use it. If you can't use tar xvf and no one has suggested that you use tar xvf , why is it important for us to know that you can't use tar xvf ?

Hi Don,
i removed the tar xvf line, but the point is.
i cant do this

for i in `In multiple directories`
tar xvf /tar/*.tar

Perhaps, it would be best if you follow up with some more information in your other thread you started: Tar extract a multiple directories Post: 302946817

Usually, when people do not respond to your post is because it is not clear or is missing the necessary information to give you a solution.
I suggest you go back to that thread and add an example of how your file directory tree looks like. Post the output of ls -l from the directory you want to perform the extraction. Also, it might help what kind of errors or warnings you get when command is executed.
Finally, it is most helpful if you explain what do you think or expect to happen and it is not occurring.

Your stated goal was to copy files with filename extensions from one directory into a subdirectory named by the file's name with the filename extension removed. I don't see any connection between that goal and running any of the commands:

rm -f $dir/*.tar
mv -f $dir*tgz* $dir/
gunzip $dir/*.tgz
      or
tar xvf /tar/*.tar

So, I am still lost...

you cant tar in script unless you will do this

tar xvf tareball -C "Directory you want to extract"