Overwrite the Value in Text File

I have a text file call counter.txt. It has only one line with the number 567.
I want to write a very simple script file to replace the number by 1 every time I run the script. So the number will become 568. Run one more time, number became 569 and so no.

Here is one way of doing it. No error
checking or locks!
#!/usr/bin/ksh
OLDVALUE=`/usr/bin/cat counter.txt`
NEWVALUE=`/usr/bin/expr $OLDVALUE + 1`
echo $NEWVALUE > counter.txt

How to read in an External Text File?

I have tried diff, and it does not give me what I need. I am unsure of the code needed to read in one line at a time of an external file and then use fields from that line to assign to variables. Those variables wold then be passed into an awk with the other file to be compared.

If you already know awk, then the most of the issue is solved. Just use awk to read in a line at a time and to assign the designate values to their respective variables.

Yes, instead of processing one line at a time and calling awk repeatedly, awk can read both of your files and do the diff logic. I could provide a solution if you provide more detail (sample from both files, how you want them matched, estimated file sizes).
But to answer your question, following code will read one line at a time from a file and assign fields to variables:

#!/bin/sh
cat myinputfile |
while read var1 var2 var3 remainder
do
echo "var1=$var1 var2=$var2 var3=$var3"
done
exit 0

Have a Unix Problem
Do you have a UNIX Question?

Books About Unix
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Unix Home: Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.