The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Knowing the half will get you into trouble - describe your disasters benefactr What's on Your Mind? 3 04-25-2008 12:48 PM
Output number of rows inserted, updated... kushal_cog UNIX for Dummies Questions & Answers 0 01-30-2008 03:28 AM
to extarct data points cdfd123 Shell Programming and Scripting 5 01-12-2008 09:39 AM
Urgent...FTP unable finish download file, hang half way foongkt5220 SUN Solaris 3 08-11-2006 07:31 AM
Extarct specific records from wide file acheepi Shell Programming and Scripting 1 10-02-2005 01:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-18-2008
tarundeepdhawan tarundeepdhawan is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
How can i extarct the output from a file which has been updated from last half an hou

hi,
I have a log file , which is appending with current data
i need the extarct which is updated from last 30 minutes
the format of the date is Jun 18, 2008 8:59:18 AM
how can i subtract 30 mins from the current date
thanks
Tarun.
  #2 (permalink)  
Old 06-18-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Search the forum for date & time calculation for your OS.
  #3 (permalink)  
Old 06-18-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
one way
Code:
#!/bin/ksh
# filetimes
minsago()
{
    perl  -e '
          use POSIX qw(strftime);
          $fmt="%c";  # change this to meet your needs
          $now=time;
          $now-=1800;  # 30 minutes = 1800 seconds
         ($sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$dntcare)=localtime($now);
          $result=strftime($fmt, $sec,$min,$hour,$day,$mon,$yr,$wday,$yday,$dntcare);
          print "$result"
         ' $1
}
start=$(minsago)
echo "$start"
Change the $fmt = "%c" -- if your locale does not print the date in the correct format.
  #4 (permalink)  
Old 06-18-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
With gnu coreutils date:

Code:
DTE=$(date "+%b %d, %Y %r" --date "now -30 minutes")
grep "$DTE" your-file
If your locale don't use C:

Code:
LC_ALL=C DTE=$(date "+%b %d, %Y %r" --date "now -30 minutes")
grep "$DTE" your-file
  #5 (permalink)  
Old 06-23-2008
tarundeepdhawan tarundeepdhawan is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Hi Ripat
Thanks for the reply, but it does not solve my purpose, it is just changing the format of the date but not subtracting 30 mins

$ DTE=$(date "+%b %d, %Y %r" --date "now -30 minutes")
$ echo $DTE
Jun 23, 2008 02:43:34 AM
$ date
Mon Jun 23 02:43:49 EDT 2008

i have a log file i need to extract data which has been updated from last 30 mins

plz advise
  #6 (permalink)  
Old 06-23-2008
ripat ripat is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2006
Location: Belgium
Posts: 438
It works on my linux box with coreutil's date. Are you using GNU date? Which version?

Try:
Code:
$ date "+%b %d, %Y %r" --date "now 30 minutes ago"
Closed Thread

Bookmarks

Tags
linux, solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0