niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Programming » shell
Getting all lines with last 14 hours
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
Author Message
contracer11@gmail.com
*nix forums addict


Joined: 02 Aug 2005
Posts: 83

PostPosted: Tue Jul 18, 2006 3:50 pm    Post subject: Getting all lines with last 14 hours Reply with quote

Hi all

Is there any command that I could get from this file all lines
with last 14 hours ?

solaris> cat file1

18/07/06 21:30
18/07/06 18:42
17/07/06 11:55
16/07/06 14:05
15/07/06 21:42
18/07/06 13:30
14/07/06 05:42
12/07/06 18:22

Thanks
Back to top
Chris F.A. Johnson
*nix forums Guru


Joined: 20 Feb 2005
Posts: 2268

PostPosted: Tue Jul 18, 2006 4:38 pm    Post subject: Re: Getting all lines with last 14 hours Reply with quote

On 2006-07-18, contracer11@gmail.com wrote:
Quote:
Hi all

Is there any command that I could get from this file all lines
with last 14 hours ?

solaris> cat file1

18/07/06 21:30
18/07/06 18:42
17/07/06 11:55
16/07/06 14:05
15/07/06 21:42
18/07/06 13:30
14/07/06 05:42
12/07/06 18:22

Last 14 hours? Those dates are 2,000 years ago! Fix whatever
program created that file, and use ISO date format.

You could use gawk:

gawk -F '[/ :]' 'BEGIN {
srand()
time = strftime("%Y%m%d%H%M",int( (srand() - (14 * 3600)) ))
}
{ if ( ($3 + 2000) $2 $1 $4 $5 > time ) print $0 }
'

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Back to top
contracer11@gmail.com
*nix forums addict


Joined: 02 Aug 2005
Posts: 83

PostPosted: Tue Jul 18, 2006 5:10 pm    Post subject: Re: Getting all lines with last 14 hours Reply with quote

Chris F.A. Johnson wrote:
Quote:
On 2006-07-18, contracer11@gmail.com wrote:
Hi all

Is there any command that I could get from this file all lines
with last 14 hours ?

solaris> cat file1

18/07/06 21:30
18/07/06 18:42
17/07/06 11:55
16/07/06 14:05
15/07/06 21:42
18/07/06 13:30
14/07/06 05:42
12/07/06 18:22

Last 14 hours? Those dates are 2,000 years ago! Fix whatever
program created that file, and use ISO date format.

You could use gawk:

gawk -F '[/ :]' 'BEGIN {
srand()
time = strftime("%Y%m%d%H%M",int( (srand() - (14 * 3600)) ))
}
{ if ( ($3 + 2000) $2 $1 $4 $5 > time ) print $0 }
'

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence

Itīs the output from my Veritas Netbackup:

dd/mm/yy hh:mm
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Wed Jul 19, 2006 2:15 pm    Post subject: Re: Getting all lines with last 14 hours Reply with quote

contracer11@gmail.com wrote:

Quote:
Chris F.A. Johnson wrote:

On 2006-07-18, contracer11@gmail.com wrote:

Hi all

Is there any command that I could get from this file all lines
with last 14 hours ?

solaris> cat file1

18/07/06 21:30
18/07/06 18:42
17/07/06 11:55
16/07/06 14:05
15/07/06 21:42
18/07/06 13:30
14/07/06 05:42
12/07/06 18:22

Last 14 hours? Those dates are 2,000 years ago! Fix whatever
program created that file, and use ISO date format.

You could use gawk:

BEGIN {
srand()
time = strftime("%Y%m%d%H%M",int( (srand() - (14 * 3600)) ))

Using systime() rather than srand() would be a lot more inuitive and you
wouldn't need to call it twice.

I don't see why you'd need the "int()" - please clarify why that's
necessary.

Quote:
}
{ if ( ($3 + 2000) $2 $1 $4 $5 > time ) print $0 }

The more typical awk way would be to just specify the condition and so
invoke the default action of printing $0 rather than explicitly typing it.

Quote:
'

Assuming the original code functions correctly, I think all you really
need is:

gawk -F '[/ :]' 'BEGIN {
time = strftime("%Y%m%d%H%M",systime() - (14 * 3600)))
}
($3 + 2000) $2 $1 $4 $5 > time'

Regards,

Ed.
Back to top
contracer11@gmail.com
*nix forums addict


Joined: 02 Aug 2005
Posts: 83

PostPosted: Wed Jul 19, 2006 3:05 pm    Post subject: Re: Getting all lines with last 14 hours Reply with quote

Ed Morton wrote:
Quote:
contracer11@gmail.com wrote:

Chris F.A. Johnson wrote:

On 2006-07-18, contracer11@gmail.com wrote:

Hi all

Is there any command that I could get from this file all lines
with last 14 hours ?

solaris> cat file1

18/07/06 21:30
18/07/06 18:42
17/07/06 11:55
16/07/06 14:05
15/07/06 21:42
18/07/06 13:30
14/07/06 05:42
12/07/06 18:22

Last 14 hours? Those dates are 2,000 years ago! Fix whatever
program created that file, and use ISO date format.

You could use gawk:

BEGIN {
srand()
time = strftime("%Y%m%d%H%M",int( (srand() - (14 * 3600)) ))

Using systime() rather than srand() would be a lot more inuitive and you
wouldn't need to call it twice.

I don't see why you'd need the "int()" - please clarify why that's
necessary.

}
{ if ( ($3 + 2000) $2 $1 $4 $5 > time ) print $0 }

The more typical awk way would be to just specify the condition and so
invoke the default action of printing $0 rather than explicitly typing it.

'

Assuming the original code functions correctly, I think all you really
need is:

gawk -F '[/ :]' 'BEGIN {
time = strftime("%Y%m%d%H%M",systime() - (14 * 3600)))
}
($3 + 2000) $2 $1 $4 $5 > time'

Regards,

Ed.


Is there any awk or nawk solution ?
I didnīt found gawk in my Solaris system.
I susbstitute gawk for awk and nawk in the code, but
I receive error messages (bailling, etc).

Thanks
Back to top
Ed Morton
*nix forums Guru


Joined: 20 Feb 2005
Posts: 1073

PostPosted: Thu Jul 20, 2006 3:26 am    Post subject: Re: Getting all lines with last 14 hours Reply with quote

contracer11@gmail.com wrote:

Quote:
Ed Morton wrote:

contracer11@gmail.com wrote:


Chris F.A. Johnson wrote:


On 2006-07-18, contracer11@gmail.com wrote:


Hi all

Is there any command that I could get from this file all lines
with last 14 hours ?

solaris> cat file1

18/07/06 21:30
18/07/06 18:42
17/07/06 11:55
16/07/06 14:05
15/07/06 21:42
18/07/06 13:30
14/07/06 05:42
12/07/06 18:22

Last 14 hours? Those dates are 2,000 years ago! Fix whatever
program created that file, and use ISO date format.

You could use gawk:

BEGIN {
srand()
time = strftime("%Y%m%d%H%M",int( (srand() - (14 * 3600)) ))

Using systime() rather than srand() would be a lot more inuitive and you
wouldn't need to call it twice.

I don't see why you'd need the "int()" - please clarify why that's
necessary.


}
{ if ( ($3 + 2000) $2 $1 $4 $5 > time ) print $0 }

The more typical awk way would be to just specify the condition and so
invoke the default action of printing $0 rather than explicitly typing it.


'

Assuming the original code functions correctly, I think all you really
need is:

gawk -F '[/ :]' 'BEGIN {
time = strftime("%Y%m%d%H%M",systime() - (14 * 3600)))
}
($3 + 2000) $2 $1 $4 $5 > time'

Regards,

Ed.



Is there any awk or nawk solution ?
I didnīt found gawk in my Solaris system.
I susbstitute gawk for awk and nawk in the code, but
I receive error messages (bailling, etc).

Just download gawk. It's free from http://www.gnu.org/software/gawk/ and
it has enough extensions to make it more than worthwhile.

Ed.
Back to top
Jon LaBadie
*nix forums beginner


Joined: 06 May 2006
Posts: 46

PostPosted: Thu Jul 20, 2006 4:24 am    Post subject: Re: Getting all lines with last 14 hours Reply with quote

Ed Morton wrote:
Quote:
contracer11@gmail.com wrote:

....

Is there any awk or nawk solution ?
I didn?t found gawk in my Solaris system.
I susbstitute gawk for awk and nawk in the code, but
I receive error messages (bailling, etc).

Just download gawk. It's free from http://www.gnu.org/software/gawk/ and
it has enough extensions to make it more than worthwhile.


Solaris doesn't come with a C or C++ compiler.
Someone who doesn't have gawk likely lacks gcc too.

For a pre-built version of gawk, the OP might consider
either the Companion CD that Sun supplies with the
installation disks (usually can be downloaded too)
which installs in /opt/sfw, or software from blastwave.org
which installs in /opt/csw.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [7 Posts] View previous topic :: View next topic
The time now is Thu Dec 04, 2008 3:15 am | All times are GMT
navigation Forum index » Programming » shell
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts blocking mails with long lines and giberish Dale Blount Postfix 4 Thu Jul 20, 2006 2:31 pm
No new posts Match lines, group and sum FriesAOLE shell 2 Thu Jul 20, 2006 7:40 am
No new posts Reading long lines doesn't work in Python Scott Simpson python 2 Wed Jul 19, 2006 4:25 pm
No new posts joining lines in ksh jctown@nb.sympatico.ca shell 13 Wed Jul 19, 2006 1:28 am
No new posts combine lines bp Perl 1 Tue Jul 18, 2006 11:48 pm

Loans | Debt Consolidation | MPAA | Promotional Codes | Credit Card
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.2119s ][ Queries: 16 (0.1082s) ][ GZIP on - Debug on ]