Reading and Comparing values of file

Hi gurus..

Am reading a file, counting number of lines and storing it in a variable. Then am passing that variable into If loop for comparision, if the number of lines are greater than 1000 it should split a file if not it should send the file name to archive folder.. but when i execute the program comparision in IF loop is geting failed.. I dont know where am i going wrong, pls help me

count=`cat $file | wc -l`
if [ "$count" > 1000 ]
then
sed -i '1d' $file
split -l 1000 $file new
for i in ne*
do
    mv $i $i".csv"
done
else
echo "$count"
move_file
fi

When am passing a file with less than 1000 records the file is not getting moved to archive.
move_file is my function

cp $file ${file%.*}_$n.${file#*.}
mv ${file%.*_$n.${file#*.} /data/archive/

here else statement is getting failed :frowning: when i pass files have 5000 records then it is working

I also tried with count=`wc -l $file`

echo "$count"

This i have just put to test the "count" but else is getting failed & its not getting print

This is wrong:

if [ "$count" > 1000 ]

Try this:

if [ "$count" -gt 1000 ]

When you give wc a list of file operands, it includes the filename in the output. To avoid the unneeded cat in:

count=`cat $file | wc -l`

and avoid the filename in the output from:

count=`wc -l $file`

you can use:
count=`wc -l < $file`

Crona : if i give value like that in If -> its giving me a error like Integer Exression xpected..

Don : still If is getting failed

Since wc includes leading spaces in its output, try it without the quotes:

if [ $count -gt 1000 ]
2 Likes