Awk command to split file name

Hi
I have few files with format access.2Nov-12:15AM.
These files will be generated daily . I need to write a script so that if today's date is less than 10 then it has to zip the file and rename it to

acess.02Nov-12:15AM.gz .please help me in this . Also please help me
in splitting the file acess.2Nov-12:15AM to
1 acess
2 2
3 Nov
4 12:15
5 AM
Thanks for the help in advance

find ./ -name "access.*" -mtime +10 -exec gzip {} \;

or

ls -t access.* | tail +11 | xargs gzip

You should find the script that generate those files instead of try to parse them : $(date '+%Y%m%d') would be a better date format choice for naming such daily files

# fname=access.2Nov-12:15AM
# for i in $(echo "$fname" | sed 's/\(access\).\([0-9][0-9]*\)\([JFMASOND][a-z][a-z]\)-\([0-9][0-9]*\):\([0-9][0-9]*\)\([AP]M\)$/\1 \2 \3 \4 \5 \6/')
> do
> let j++
> fname[$j]=$i
> done
# echo ${fname[1]}
access
# echo ${fname[2]}
2
# echo ${fname[3]}
Nov
# echo ${fname[4]}
12
# echo ${fname[5]}
15
# echo ${fname[6]}
AM
#

in ksh :

# fname="access.2Nov-12:15AM"
# echo "$fname" | sed 's/\(access\).\([0-9][0-9]*\)\([JFMASOND][a-z][a-z]\)-\([0-9][0-9]*\):\([0-9][0-9]*\)\([AP]M\)$/\1 \2 \3 \4 \5 \6/' | read a b c d e f
# echo "nam=$a day=$b mon=$c hr=$d min=$e last=$f"
nam=access day=2 mon=Nov hr=12 min=15 last=AM
#

when i tried the command
echo "$fname" | sed 's/\(access\).\([0-9][0-9]*\)\([JFMASOND][a-z][a-z]\)-\([0-9][0-9]*\):\([0-9][0-9]*\)\([AP]M\)$/\1 \2 \3 \4 \5 \6/' | read a b c d e f

i got all blank values as output in a,b,c,d,e,f

---------- Post updated at 11:12 PM ---------- Previous update was at 11:08 PM ----------

I thnk the read command is not working is there any way i can pass the output to diff variables?

try this,

fname='access.2Nov-12:15AM'
echo "$fname" | sed 's/\(access\).\([0-9][0-9]*\)\([JFMASOND][a-z][a-z]\)-\([0-9][0-9]*\):\([0-9][0-9]*\)\([AP]M\)$/\1\n\2\n\3\n\4\n\5\n\6/' | while read fields; do echo $fields; done

This may also help i believe

var="access.2Nov-12:15AM"
echo ${var%.*}
access
var1=`echo ${var%-*}`
echo ${var1#*.} | sed 's/\([0-9]*\).*/\1/'
2
echo ${var1#*.} | cut -c2-4
Nov
echo ${var#*-} | cut -c1-5
12:15
echo ${var#*-} | cut -c6-7
AM

Hi
that worked thanks . If my file is /clocal/www/logs/IHS/webs5486/access.29Oct-12:15AM.gz

how can i get the path /clocal/www/logs/IHS/webs5486/? from the above line?

dirname - this command gives you the directories name alone..try..

dirname /clocal/www/logs/IHS/webs5486/access.29Oct-12:15AM.gz

Bash/ksh:

F=( $(echo "${fname##*/}" | sed 's/\([0-9]\)\([A-Z]\)/\1 \2/g;s/[-.:]/ /g') )
$ echo ${F[0]}
access
$ echo ${F[1]}
2
echo ${F[5]}
AM

ksh:

echo "${fname##*/}" | sed 's/\([0-9]\)\([A-Z]\)/\1 \2/g;s/[-.:]/ /g' |   read f1 f2 f3 f4 f5 f6 x

bash:

read f1 f2 f3 f4 f5 f6 x < <(echo "${fname##*/}" | sed 's/\([0-9]\)\([A-Z]\)/\1 \2/g;s/[-.:]/ /g')

----

Any posix compliant shell:

echo "${fname##*/}" | sed 's/\([0-9]\)\([A-Z]\)/\1 \2/g;s/[-.:]/ /g' | {
  read f1 f2 f3 f4 f5 f6 x
  echo $f1
  echo $f6
}
access
AM

------

If you no longer need the command line parameters in you script:

set -- $( echo "${fname##*/}" | sed 's/\([0-9]\)\([A-Z]\)/\1 \2/g;s/[-.:]/ /g' )
$ echo $1
access
$ echo $5
15
$ echo $6
AM

I guess you didn't try the first solution i mentionned with the loop for i in ... (see my previous post #2)

Could you please tell why the parameter substitution is needed, as echo "${fname##*/}" and echo "${fname}" gives the same output.

Because of post #6