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
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?
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