|
|
|
|
|
|
| Author |
Message |
contracer11@gmail.com *nix forums addict
Joined: 02 Aug 2005
Posts: 83
|
Posted: Tue Jul 18, 2006 3:50 pm Post subject:
Getting all lines with last 14 hours
|
|
|
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
|
Posted: Tue Jul 18, 2006 4:38 pm Post subject:
Re: Getting all lines with last 14 hours
|
|
|
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
|
Posted: Tue Jul 18, 2006 5:10 pm Post subject:
Re: Getting all lines with last 14 hours
|
|
|
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
|
Posted: Wed Jul 19, 2006 2:15 pm Post subject:
Re: Getting all lines with last 14 hours
|
|
|
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.
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
|
Posted: Wed Jul 19, 2006 3:05 pm Post subject:
Re: Getting all lines with last 14 hours
|
|
|
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
|
Posted: Thu Jul 20, 2006 3:26 am Post subject:
Re: Getting all lines with last 14 hours
|
|
|
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
|
Posted: Thu Jul 20, 2006 4:24 am Post subject:
Re: Getting all lines with last 14 hours
|
|
|
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 |
|
 |
|
|
The time now is Thu Dec 04, 2008 3:15 am | All times are GMT
|
|
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
|
|