LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 04-09-2009, 07:53 AM   #1
Eddie Adams
LQ Newbie
 
Registered: Sep 2007
Posts: 22

Rep: Reputation: 0
sed/awk group on first column


current:
15551256 user nl 1 Query SELECT SQL_CALC_FOUND_ROWS
15551256 user nl 2 Query SELECT SQL_CALC_FOUND_ROWS
15551256 user nl 3 Query SELECT SQL_CALC_FOUND_ROWS
15551256 user nl 4 Query SELECT SQL_CALC_FOUND_ROWS
15551330 user nl 0 Query SELECT SQL_CALC_FOUND_ROWS
15551367 user nl 0 Query SELECT SQL_CALC_FOUND_ROWS
15551372 user nl 0 Query SELECT SQL_CALC_FOUND_ROWS
15551486 user nl 1 Query SELECT SQL_CALC_FOUND_ROWS
15551486 user nl 2 Query SELECT SQL_CALC_FOUND_ROWS

desired:
15551256 user nl 4 Query SELECT SQL_CALC_FOUND_ROWS
15551330 user nl 0 Query SELECT SQL_CALC_FOUND_ROWS
15551367 user nl 0 Query SELECT SQL_CALC_FOUND_ROWS
15551372 user nl 0 Query SELECT SQL_CALC_FOUND_ROWS
15551486 user nl 2 Query SELECT SQL_CALC_FOUND_ROWS
 
Old 04-09-2009, 08:29 AM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
What criteria are you using? Where there are duplicates, what determines which one to use?

If you simply want a line where the first column is unique, look at the uniq program. If you are testing for a range of values in the first column, then use awk.
 
Old 04-09-2009, 09:59 AM   #3
Eddie Adams
LQ Newbie
 
Registered: Sep 2007
Posts: 22

Original Poster
Rep: Reputation: 0
The first column is unique. The fourth column has a max value.
 
Old 04-09-2009, 10:06 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,372

Rep: Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911Reputation: 1911
Code:
sort -nr file | uniq -w8 | tac
 
Old 04-09-2009, 10:23 AM   #5
Eddie Adams
LQ Newbie
 
Registered: Sep 2007
Posts: 22

Original Poster
Rep: Reputation: 0
Thanks.
 
  


Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
awk comparing a column value with a stored variables value bugg_deccan Programming 4 12-05-2008 07:08 AM
Sed column replacement. keysorsoze Programming 11 12-01-2008 09:50 AM
Multiplying data column in awk - can rounding be suppressed? johnpaulodonnell Linux - Newbie 2 02-28-2007 07:56 AM
sed / awk command to print line number as column? johnpaulodonnell Linux - Newbie 2 01-22-2007 07:07 AM
awk column printing schneidz Programming 7 09-29-2005 06:14 AM


All times are GMT -5. The time now is 10:52 PM.

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