LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-29-2013, 01:54 AM   #1
rajes4india
Member
 
Registered: Aug 2011
Posts: 32

Rep: Reputation: Disabled
compare two values using any script in a file.


Hello all,

i am new to scripting. In have to compare third column with the previous line 3rd column value and if the value is greater than or equal to 100 i have to print the line. i have a data like below i my file.

B 23 3233555383 ArpIndex
B 23 3233555390 ArpLock
E 23 3233555397 ArpLock
B 23 3233555407 ArpUnLock
E 23 3233555415 ArpUnLock
E 23 3233555422 ArpIndex

manual example:

3233555390 - 3233555383 = 7. like this i have to compare and if the value is >= 100. i have to print the line.

thanks in advance.

thanks
Rajesh
 
Old 03-29-2013, 03:54 AM   #2
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,500

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
do you know awk? it would be quite easy:
awk ' m-$2 > 100 { print } { m=$2 } '
 
Old 03-29-2013, 04:43 AM   #3
rajes4india
Member
 
Registered: Aug 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
do you know awk? it would be quite easy:
awk ' m-$2 > 100 { print } { m=$2 } '
Thanks for your response.

unluckly its not working.

i have created the above line in a file named "file".

[root@RaJesH tmp]# cat file
B 23 3233555383 ArpIndex
B 23 3233555390 ArpLock
E 23 3233555397 ArpLock
B 23 3233555407 ArpUnLock
E 23 3233555415 ArpUnLock
E 23 3233555422 ArpIndex

and i am running awk as per suggestion.

awk ' m-$3 > 3 { print } { m=$3 } ' file.

it should not print line one and two (3233555390 - 3233555383 ) = 7. Even the difference is more than 3.

any idea/ suggestion.
 
Old 03-29-2013, 05:58 AM   #4
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,500

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
that should have been found:
$3-m
 
Old 03-29-2013, 06:36 AM   #5
rajes4india
Member
 
Registered: Aug 2011
Posts: 32

Original Poster
Rep: Reputation: Disabled
[QUOTE=pan64;4921002]that should have been found:
$3-m[/
it works ....

thanks a lot.
 
Old 03-29-2013, 06:40 AM   #6
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,500

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
glad to help you
if you really want to say thanks just press yes (bottom right corner) and also please mark thread solved if you were satisfied.
 
  


Reply

Tags
awk, linux, scripting, shell script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LINUX - How to compare the values in 2 files & exit from the script dsfreddie Linux - Newbie 4 07-25-2012 05:14 PM
How to read CSV data and compare the column values and then write them in new file VijayaRaghavanLakshman Linux - Newbie 9 01-26-2012 09:02 PM
Ways to compare values in large file/db Linux_Kidd Programming 8 01-23-2012 11:40 AM
Compare Decimal Values rbautch Linux - General 10 04-22-2008 04:11 AM
Script to compare file size nazs Programming 6 05-24-2006 10:10 AM


All times are GMT -5. The time now is 09:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration