Bash script integer value problem [SOLVED]
Hello,
As a newbie in a shell scripting I have the following problem:
I am writing a bash script to read from file line by line. The problem is that I need to check every line form this file for some condition, and because the file is changing its length in time (log file for example) the number of the rows in it varies.
So I basically want to get the number of lines and add it in a "for" cycle, but it always gives an error, because it takes the number as a string and not as an integer value.
So the only thing I can't figure out how to do is to make the "for" cycle take the value as an integer in some way so it can process it.
Any help is greatly appreciated.
Thanks in advance!
Here is a sample of the code:
-----------------------------
#!/bin/bash
# get the number of rows in the file and print them on the screen
wc -l $FILE > $FILE2
cat $FILE2 | awk 'BEGIN { FS = " " } { print $1 } END { }'
# trying to enter manually the number of rows as an integer
echo -n "Enter the number above > "
read NUM1
# doing the for cycle
for i in {1..$NUM1}
do
if <read the $i line from file and check if something exists>
then
<do something>
else
<do other thing>
fi
done
-------------------------------
Last edited by luboiron; 09-14-2012 at 05:42 AM.
Reason: problem solved - update tilte
|