LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-14-2019, 03:47 PM   #1
msims75252
LQ Newbie
 
Registered: Jan 2019
Posts: 2

Rep: Reputation: Disabled
Print only the lines with succeeding dates


The 1st column represents a 4 position date (e.g. 10/02). I want print only the lines with succeeding dates (e.g. 10/01, 10/02, 10/15, 10/16, 10/20, 10/21, 10/29 & 10/30).

File named test

Test:
1001 1715 3bc4r
1002 1927 3aclr
1002 2127 01iqq
1002 2227 3j1ai
1004 2021 3x1mq
1006 1947 yj1vd
1011 0007 s7tem
1015 1448 05p2l
1016 1248 3j8nk
1020 2137 0aakg
1021 2138 0aakg
1026 2045 xuakr
1029 2110 3alzt
1029 2310 0aakg
1030 0010 3jf24

Desired Output:

1001 1715 3bc4r
1002 1927 3aclr
1002 2127 01iqq
1002 2227 3j1ai

1015 1448 05p2l
1016 1248 3j8nk

1020 2137 0aakg
1021 2138 0aakg

1029 2110 3alzt
1029 2310 0aakg
1030 0010 3jf24


Any help would be appreciated.

Last edited by msims75252; 01-15-2019 at 02:38 AM.
 
Old 01-14-2019, 03:57 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
You can do this with awk. Here is the plan (needs some fine-tuning):

Store a line in an array.
Keep adding lines to the array as long as the date is the same as the previous line or one day later.
As soon as the input line has a date that is two or more days later, dump out the array and reset it.

One difficulty is that you need a function that checks if a date follows another. How do you decide that for the last day of February?
 
Old 01-14-2019, 05:36 PM   #3
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
Code:
for i in {1015..1100};do grep "$i" test;done
a problem with this is that it checks the whole line for the number.

Last edited by whansard; 01-14-2019 at 05:46 PM.
 
Old 01-15-2019, 02:30 AM   #4
msims75252
LQ Newbie
 
Registered: Jan 2019
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks! It has been 15 year since I had access to a command line, so I am pretty rusty. I'll explore the awk array until something else materializes.

Last edited by msims75252; 01-15-2019 at 02:36 AM.
 
  


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
LXer: On dates and stuffed non-dates LXer Syndicated Linux News 0 10-08-2014 02:21 AM
[SOLVED] generate dates between two dates ip_address Programming 4 03-21-2013 04:28 PM
[SOLVED] Trying to install Google Chromium Web Browser - not quite succeeding... Robert.Thompson Slackware 8 02-07-2011 01:54 PM
not succeeding to install .tar.gz file ajaytiwary Linux - Newbie 2 10-02-2007 08:33 AM
LXer: Opinion: Why Some Linux News Sites Aren't Succeeding LXer Syndicated Linux News 0 12-18-2005 05:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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