Now in another file we store the last run date (LAST_DATE.TXT) in the format 20130405(YYYYMMDD). The current value is 20130405.
I want to pick up only the files for the 6th and not the 4th and the 5th. And then store the date 06022013 (from the file) into the LAST_DATE.TXT file in the format 20130406.
Hence i would process each day only those files which are latest and after the last run date.
As your specification is utterly vague, it's difficult to suggest a solution. I'd propose you use sed or awk to transpose the single elements of your date field.
in order to find out the date of the files i have used the below code
ls|rev|cut -d "." -f2|cut -d "_" -f1|rev
this gives me the dates of all the files in the format ddmmyyyy.
now if i can change this to YYYYMMDD then my problem is solved. I would be able to bring the files which have this above calculated date greater than the last run date.
can this be done??
---------- Post updated at 01:27 PM ---------- Previous update was at 01:17 PM ----------
if the date can be changed to YYYYMMDD then i can use the code below to bring the relative files.
set -vx
TARGET_DIR=$2
SOURCE_DIR=$1
LOGDIR=/info_d05/visage/SrcFiles/IQAlign/Log_Files
b=`cat $LOGDIR/last_date.txt`
for i in $SOURCE_DIR/Novawise*
do
fname=`basename $i`
p=`echo $fname|rev|cut -d "." -f2|cut -d "_" -f1|rev|something`
if [ $p -gt $b ]
then
cp $SOURCE_DIR/$fname $TARGET_DIR/
fi
done
well the first one worked perfectly. but the second one did not..i am running the entire script and would let u know the outcome.i am using the first one. But i didn't understand the functioning. can you please explain how this worked?
You have to prepend whatever input you produce to the second one, of course, like the ls | used above. I added it to the code.
The first code breaks the input line at _ and . as told by the field separator, set with -F . $NF is the last field ("txt"), $(NF-1) the before last field containing the date string. The use of the substr function is self explanatory, I think.
The second works similarly, but leaves the .txt extension intact.
well thanks a lot for the help...the code works perfectly...this was a part of the huges script in which i was struck...now the entire thing is working as expected..i had little knowledge of awk programming so didn't understand it in the beginning...can you help me out with a good pdf or something to read from and understand awk and nawk...would appreciate your help....thanks..