Loop SCript

Hi,

I am newer to UNIX scripting. Here is what I am trying to accomplish:

I want to log a timestamp and a row count for a spcific file, out to another file.

Below is my script. WhenI run it, it says that line 6 is missing a ']' which I don't see how, and then echos File Does Not Exist (which the file does exist and is at 777).

Any help on this would be grealy appreciated - I don't have the best tools to troubleshoot and debug so also if there is a easy to use tool that you could suggest please do so, I don't like asking others to debug my code.

Script:

#!/bin/bash
a=0 
while [ $a -lt 10 ]
do
if [ -f /pr/datastage/AUST/output/LargeFileForTesting_AUST.txt_Processing]
then
   echo "File exists"
wc -k /pr/datastage/AUST/output/LargeFileForTesting_AUST.txt_Processing |sed -e "s/^/$(date)/">>/pr/datastage/AUST/workarea/LargeFileForTesting_AUST.txt_Processing_Row_Count
else
   echo "File does not exists"
   break
   a=1
fi
done
if [ -f /pr/datastage/AUST/output/LargeFileForTesting_AUST.txt_Processing ]

The problem you are reporting is due to a missing space between Processing and ]
However, you might have another problem. You never increase the loop counter so it will never stop looping unless that the file does not exist.

Thanks, I will look into that and remove the space!
Correct, I am depending on the loop to break when the file doesn't exist. The file will be moved after processing is completed and then it will no longer exist.
Thanks for your reply and assitance.

I think you misunderstood me. You do not have a space, and there should be one as I show in the highlighted portion I posted.
Also, entering the loop, if the /pr/datastage/AUST/outputLargeFileForTesting_AUST.txt_Processing exists once, the loop will be a forever loop, since you are not increasing the counter to ever become 10.

And even IF the counter would be raised, upon first file (*_Processing) not found, its reset back to 1 - if it wouldnt break before that - leaving a untouched.
But since you work 10 times on the same file, that will not happen - and is therefor not required.

In fact, other than to do the very same task 10 times with the very same file, a is not used at all.

So my question: is that loop really required?

EDIT:

grep "$(date)" /pr/datastage/AUST/outputLargeFileForTesting_AUST.txt_Processing | wc -l  || echo "Either file dont exist or date not found."

hth

Sorry about that I did add a space and not remove it after I wrote that, I meant to write add a space. And the script works.

I did also move the a=1 I saw that after I posted the script and didn't update the post, but thank you for pointing that out.

Thank you for your help. This script is now working as I wanted.

Thanks again for your help!