LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 06-12-2014, 03:29 AM   #1
fantasy1215
Member
 
Registered: Oct 2011
Posts: 75

Rep: Reputation: Disabled
How to remove lines according a column?


I have a file like this:
time case_num other_columns
Code:
20140612162021    3000               others
20140612162022    3001               others
20140612162023    3001               others
20140612162024    3002               others
20140612162025    3002               others
20140612162026    3002               others
According case_num, when the same case_num has more than one line, I'd like to leave such line which has the most recently time.

after remove lines the result file is like
Code:
20140612162021    3000               others
20140612162023    3001               others
20140612162026    3002               others
I'd appreciate your help, many thanks.
 
Old 06-12-2014, 03:34 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
And what have you done to try and solve this problem? If you are not sure what tool to look at, I would suggest awk as it is designed with columned data in mind
 
Old 06-12-2014, 08:04 AM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
This is clumsy but it works.

With this InFile ...
Code:
20140612162021    3000               others
20140612162022    3001               others
20140612162023    3001               others
20140612162024    3002               others
20140612162025    3002               others
20140612162026    3002               others
... this code ...
Code:
tac $InFile |awk '!a[$2]++' |tac >$OutFile
... produced this OutFile ...
Code:
20140612162021    3000               others
20140612162023    3001               others
20140612162026    3002               others
Daniel B. Martin
 
  


Reply



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
Split single line into multiple lines with 3 column each udiubu Programming 7 11-26-2017 09:41 AM
find similar lines according to delimited column's value Oranoran Linux - Newbie 10 10-24-2013 07:28 AM
[SOLVED] Replace pattern in specific lines and column with AWK cgcamal Programming 10 04-26-2010 01:11 AM
How to remove lines and parts of lines from python strings? golmschenk Programming 3 11-26-2009 11:29 PM
Concatenate column 1 and column 2 of related lines cgcamal Programming 4 11-20-2008 10:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration