The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script move and rename based on matching criteria braidomik Shell Programming and Scripting 3 08-26-2008 12:35 PM
I cant updated the score on space invaders lo-lp-kl Post Here to Contact Site Administrators and Moderators 0 06-26-2008 02:35 PM
Remove lines, Sorted with Time based columns using AWK & SORT karthikn7974 Shell Programming and Scripting 1 05-10-2008 12:04 AM
Remove files based on date hshapiro UNIX for Dummies Questions & Answers 4 12-09-2005 12:21 PM
Select records based on search criteria on first column shashi_kiran_v UNIX for Dummies Questions & Answers 2 12-02-2005 01:49 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-01-2008
smriti_shridhar smriti_shridhar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 47
Red face remove lines based on score criteria

Hi guys,

Please guide for Solution.

PART-I

INPUT FILE (has 2 columns ID and score)
TC5584_1 93.9
DV161411_2 79.5
BP132435_5 46.8
EB682112_1 34.7
BP132435_4 29.5
TC13860_2 10.1

OUTPUT FILE (It shudn't contain the line ' BP132435_4 29.5 ' as BP132435 is repeated and it has lower score. If an ID is repeated more than twice, one with highest score should remain)
TC5584_1 93.9
DV161411_2 79.5
BP132435_5 46.8
EB682112_1 34.7
TC13860_2 10.1

PART-II

====FILE1======
TC5584_1 93.9
DV161411_2 79.5
BP132435_5 46.8
EB682112_1 34.7
TC13860_2 10.1

=====FILE2======
EB681299_3 129 269
EB425502_1 71 182
TC5584_1 66 188
BP132435_5 37 106
EB682112_1 22 150
BP132435_4 117 175
TC13860_2 16 93
DV161411_2 36 239

===OUTPUT_FILE===== (It contains column1 from FILE1 and its corresponding row from FILE2)
TC5584_1 66 188
DV161411_2 36 239
BP132435_5 37 106
EB682112_1 22 150
TC13860_2 16 93

your help is highly appreciated.

Thanks in advance.

Last edited by smriti_shridhar; 12-01-2008 at 07:22 AM.. Reason: formating
  #2 (permalink)  
Old 12-01-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 609
Try:
Part 1:


Code:
for each in $(awk -F"_" '{ print $1; }' input_file | sort -u); do sort -k1,1 -k2n input_file | grep $each | tail -1 >>output; done

For Part 2:


Code:
for each in $(awk -F"_" '{ print $1; }' file1 | sort -u); do sort -k1,1 -k2n file2 | grep $each | tail -1 >>output; done

  #3 (permalink)  
Old 12-02-2008
smriti_shridhar smriti_shridhar is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 47
Thanks

I tried the code but its giving an error saying -
Illegal variable name.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:22 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0