Reading and Comparing values of file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reading and Comparing values of file
# 1  
Old 02-06-2014
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

Code:
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
Code:
cp $file ${file%.*}_$n.${file#*.}
mv ${file%.*_$n.${file#*.} /data/archive/

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

I also tried with count=`wc -l $file`
Code:
echo "$count"

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

Last edited by azherkn3; 02-06-2014 at 02:24 PM..
# 2  
Old 02-06-2014
This is wrong:

Code:
if [ "$count" > 1000 ]

Try this:
Code:
if [ "$count" -gt 1000 ]

# 3  
Old 02-06-2014
Quote:
Originally Posted by azherkn3
Hi gurus..

... ... ...
Code:
count=`cat $file | wc -l`
 ... ... ...

... ... ...

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

... ... ...
When you give wc a list of file operands, it includes the filename in the output. To avoid the unneeded cat in:
Code:
count=`cat $file | wc -l`

and avoid the filename in the output from:
Code:
count=`wc -l $file`

you can use:
count=`wc -l < $file`
# 4  
Old 02-07-2014
Crona : if i give value like that in If -> its giving me a error like Integer Exression xpected..

Don : still If is getting failed
# 5  
Old 02-07-2014
Since wc includes leading spaces in its output, try it without the quotes:
Code:
if [ $count -gt 1000 ]

These 2 Users Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

2. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

3. Shell Programming and Scripting

Awk: Comparing arguments with in line values of file and printing the result

I need to develop a script where I will take two date arguments as parameter date1 and date2 which will in format YYYYMM. Below is the input file say sample.txt. sample.txt will have certain blocks starting with P1. Each block will have a value 118,1:TIMESTAMP. I need to compare the... (7 Replies)
Discussion started by: garvit184
7 Replies

4. Shell Programming and Scripting

Reading off values from a large file

Hi, I have a large output file (star.log), with many lines of the following type *** T vavg unburnt: 723.187 / burnt: 2662.000 What I would like to do is pick the values 723.187 and 2662.000 and What I've got so far is awk '/unburnt:.*burnt:/{Tu=$6;Tb=$NF}END{print Tu, Tb}'... (6 Replies)
Discussion started by: lost.identity
6 Replies

5. Shell Programming and Scripting

Reading values from a file

Hi I have a file in the following format AFUE 0. AOXI 0. VFUE 100.0 VOXI 274.601 TFUE 298. TOXI 2229.544 TMAX 2400. What I want to do is write a bash script, that use either perl/awk or sed to read the number after VFUE and VOXI (which is 100.0 and... (1 Reply)
Discussion started by: lost.identity
1 Replies

6. Emergency UNIX and Linux Support

Comparing date values stored in a file

Hi all, I have written a script which stores data along with requisite dates in a file. I need to compare the stored date values in the file to obtain the row with the highest date value i.e. the recent most entered record in the file. Please help cause i dont know how we can compare dates in... (10 Replies)
Discussion started by: sumi_mn
10 Replies

7. Shell Programming and Scripting

Reading text file and comparing the dates in Kshell

I have a text file in which holidays are listed as YYYYMMDD. Here is the sample data of the file. 20090911 20090912 20090913 I need to read this file and see if the current day is listed in this text file. If today and any of the rows in my text file match, I need to do further... (2 Replies)
Discussion started by: Pramodini Rode
2 Replies

8. Shell Programming and Scripting

Reading Hours and Minutes from file and comparing with current

Hi, Time till when the application should run is indicated in a file. First line is hour and second line is minute. file: 10 55 Means my application should run till 10:55. Now in a shell script, i am trying to make that logic but with no luck. min=`tail -n 1 /file_with_time`... (1 Reply)
Discussion started by: SGD
1 Replies

9. UNIX for Dummies Questions & Answers

Reading from a file and assigning values

HI I have something like this in a file ABC = 1 DEF = 2 GHI = 3 JKL = 4 MNO = 5 QRS = 6 TUV = 7 I need to assign ABC to V_abc (that is to a variable) GHI to V_ghi (that is to another variable) TUV to say V_tuv ... (6 Replies)
Discussion started by: ssuresh1999
6 Replies

10. Shell Programming and Scripting

Comparing data in file with values in table

Hi, I want to calculate the number of pipe delimiters in a file for all lines seperately. For eg:i have a file Project.txt Mohit|chawla|123|678 File1|File2|345|767|678 And my file contains many lines like this it shd give me the output as 4 5 or give me the output for all the... (0 Replies)
Discussion started by: Mohit623
0 Replies
Login or Register to Ask a Question