Results 11 to 13 of 13
This is awesome. I never thought this script would look this short and simple.
THANK YOU both blinky and ghostdog74!!
However, I tried to execute this as below. But the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 08-02-2010 #11Just Joined!
- Join Date
- Jul 2010
- Posts
- 16
This is awesome. I never thought this script would look this short and simple.
THANK YOU both blinky and ghostdog74!!
However, I tried to execute this as below. But the variables assigned as $3, $4 ... all are coming as empty. Can you pls suggest?
#!/bin/bash
destDir="../poscntl"
`cd ../posout`
for i in ODS.POS*
do
OIFS="$IFS"
IFS="."
pharmacyid=$3
tablename=$4
timestamp=$5
echo "pharmacyid $pharmacyid"
controlFile="${destDir}/ODS.POS.${pharmacyid}.${timestamp}.ctl"
IFS="$OIFS"
for datafile in ODS.POS.${pharmacyid}*
do
rcount=$(wc -l "${datafile}")
md5sum=$1
echo " The file name is : ${datafile}" >> ${controlFile}
echo " The row count is : ${rcount}" >> ${controlFile}
echo " The table name is : ${tableName} " >> ${controlFile}
echo " The time stamp is : ${timestamp} " >> ${controlFile}
echo " The md5sum is : ${md5sum}" >> ${controlFile}
echo " -----------------------------------------------------------------" >> ${controlFile}
done
done
Thanks
Maya
- 08-02-2010 #12Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 161
I don't think this is what you want, it will process files (for each pharmacyid) multiple times. if you have 2 files for a pharmacyid, it will produce 4 entries in the ctl file.
======================Code:#!/bin/bash destDir="../poscntl" cd ../posout for i in ODS.POS* do OIFS="$IFS" IFS="." set -- ${i} pharmacyid=$3 tablename=$4 timestamp=$5 echo "pharmacyid $pharmacyid" controlFile="${destDir}/ODS.POS.${pharmacyid}.${timestamp}.ctl" IFS="$OIFS" for datafile in ODS.POS.${pharmacyid}* do rcount=$(wc -l "${datafile}") md5sum=$1 echo " The file name is : ${datafile}" >> ${controlFile} echo " The row count is : ${rcount}" >> ${controlFile} echo " The table name is : ${tableName} " >> ${controlFile} echo " The time stamp is : ${timestamp} " >> ${controlFile} echo " The md5sum is : ${md5sum}" >> ${controlFile} echo " -----------------------------------------------------------------" >> ${controlFile} done done
This one process files (for each pharmacyid) once. if you have 2 files for a pharmacyid, it will produce 2 entries in the ctl file.
for pharmacyid in `ls ODS.POS.* | cut -d "." -f 3 | sort -u` gives you the unique pharmacyid, you then process all the files for that pharmacyid
Code:#!/bin/bash destDir="../poscntl" cd ../posout for pharmacyid in `ls ODS.POS.* | cut -d "." -f 3 | sort -u` do echo "pharmacyid $pharmacyid" controlFile="${destDir}/${pharmacyid}.ctl" echo > ${controlFile} for datafile in ODS.POS.${pharmacyid}.* do OIFS="$IFS" IFS="." set -- ${datafile} tableName="${4}" timestamp="${5}" IFS="$OIFS" set -- $(wc -l "${datafile}") rcount="$1" set -- $(md5sum "${datafile}") md5sum="$1" echo " The file name is : ${datafile}" >> ${controlFile} echo " The row count is : ${rcount}" >> ${controlFile} echo " The table name is : ${tableName} " >> ${controlFile} echo " The time stamp is : ${timestamp} " >> ${controlFile} echo " The md5sum is : ${md5sum}" >> ${controlFile} echo " -----------------------------------------------------------------" >> ${controlFile} done doneIn a world without walls and fences, who needs Windows and Gates?
- 08-03-2010 #13Just Joined!
- Join Date
- Jul 2010
- Posts
- 16
Thanks you SO MUCH! its Perfect!
Maya


Reply With Quote
