I have a text file call counter.txt. It has only one line with the
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!
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:
cat myinputfile |
while read var1 var2 var3 remainder
echo "var1=$var1 var2=$var2 var3=$var3"
Do you have a UNIX Question?
Unix Home: Unix System Administration
Hints and Tips