I have 2 for loop in my program , first one will list files based on timestamp and second one list the files based on type(RPT / SUB_RPT).Here is my code:
#!/bin/ksh
STG_DIR=/home/stg
for pattern in `find $STG_DIR -type f -name 'IBC*csv' | awk -F'[-.]' '{print $(NF-1)}' | sort -u`
do
echo "Time Stamp: $pattern"
for file_set in `find $STG_DIR -type f -name "IBC*${pattern}*" | awk -F'/' '{print$5}'`
do
echo "File Type:$file_set"
#echo $file
cd $STG_DIR
file_part1=`echo $file_set | awk -F'[-.]' '{print $(NF-2)}'`
file_name=${file_part1}_`date '+%Y%m%d'`_`date '+%H%M%S'`.txt
#echo "Created file: $file_name"
done
sleep 1
done
exit 0
Output for the above script is:
Can you please guide me on how to print if a type of file is not present for a time stamp. In above case I would like to print UNAPPLIED_CASH_311_SUB_RPT-0201507.csv is not present for 0201507.
Why only report that UNAPPLIED_CASH_311_SUB_RPT-0201507.csv is not present for 0201507 ? Why not also report that UNAPPLIED_CASH_311_RPT-1407278.csv is missing for 1407278 ?
And, there is no reason to invoke date twice in the code marked in red above. Invoking date twice is less efficient, runs slower, and can produce anomalous results (giving a date on one day and a time from the next day if the script is run close to midnight). You might want to change:
But, of course, since nothing is ever done with the variable file_name and nothing is ever done with the variable file_part1 except for its use in creating the variable file_name , maybe it doesn't matter???
On top of what Don Cragun said, how do you know which file types (here: UNAPPLIED_CASH_311_SUB_RPT-0201506.csv and UNAPPLIED_CASH_311_RPT-0201506.csv ) to expect? Are they listed in a file? Somewhere/somehow else? Or is (RPT / SUB_RPT) just put in a variable?