How can i extarct the output from a file which has been updated from last half an hou


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How can i extarct the output from a file which has been updated from last half an hou
# 1  
Old 06-18-2008
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  
Old 06-18-2008
Search the forum for date & time calculation for your OS.
# 3  
Old 06-18-2008
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  
Old 06-18-2008
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  
Old 06-23-2008
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  
Old 06-23-2008
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"

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extarct block data using awk

I have 3 block data with Process Beginning and Process Ending I need to Print Begining and ending lines of block data other than sqlExtracts blocks Process Beginning - 2016-04-02-00.36.13---->Print this line Putting Files To daADadD for File will move to /sadafJJHFASJFFASJ/ Extract... (8 Replies)
Discussion started by: sushma123
8 Replies

2. Shell Programming and Scripting

Compare two and write updated output in third file

Hi Linux Experts. I have a requirement where i need to update the thousands of table definitions to extend the column length and character set therefore i am looking for some sort of linux script which i can use to update the length and chacterset. I have two files In first file i have 7... (1 Reply)
Discussion started by: Black-Linux
1 Replies

3. Shell Programming and Scripting

Save output of updated csv file as csv file itself, part 2

Hi, I have another problem. I want to sort another csv file by the first field. result.csv SourceFile,Airspeed,GPSLatitude,GPSLongitude,Temperature,Pressure,Altitude,Roll,Pitch,Yaw /home/intannf/foto5/2015_0313_090651_219.JPG,0.,-7.77223,110.37310,30.75,996.46,148.75,180.94,182.00,63.92 ... (2 Replies)
Discussion started by: refrain
2 Replies

4. Shell Programming and Scripting

Save output of updated csv file as csv file itself

Hi, all I want to sort a csv file based on timestamp from oldest to newest and save the output as csv file itself. Here is an example of my csv file. test.csv SourceFile,DateTimeOriginal /home/intannf/foto/IMG_0739.JPG,2015:02:17 11:32:21 /home/intannf/foto/IMG_0749.JPG,2015:02:17 11:37:28... (10 Replies)
Discussion started by: refrain
10 Replies

5. Shell Programming and Scripting

To split a file in exact half using awk

file: 1 2 3 4 5 6 7 8 9 10 code: awk 'END{if( < NR/2) {print $0}}' file The above has some error Output needed: (8 Replies)
Discussion started by: Roozo
8 Replies

6. UNIX for Dummies Questions & Answers

Output number of rows inserted, updated...

Hi all, I am new to Unix. I have written pl/sql script to be run in Unix. I have used Merge statement and subsequently would like to know the number of rows updated or inserted. Any suggestions in this regard would be great Thanks in advance Kushal (0 Replies)
Discussion started by: kushal_cog
0 Replies

7. Shell Programming and Scripting

to extarct data points

suppose u have a file which consist of many data points separated by asterisk Question is to extract third part in each line . 0.0002*0.003*-0.93939*0.0202*0.322*0.3332*0.2222*0.22020 0.003*0.3333*0.33322*-0.2220*0.3030*0.2222*0.3331*-0.3030 0.0393*0.3039*-0.03038*0.033*0.4033*0.30384*0.4048... (5 Replies)
Discussion started by: cdfd123
5 Replies

8. Solaris

Urgent...FTP unable finish download file, hang half way

Hi all, I have 1 problem in my solaris 8 server. The problem is in every nite that will run a cron job to download file from external ftb server. This crob job starter running find, but after running for 4 minute, that ftp services is hang that, until we need kill this process. My question... (3 Replies)
Discussion started by: foongkt5220
3 Replies

9. Shell Programming and Scripting

Extarct specific records from wide file

I have a file which is 5 million records. And each records has 412 fields has delimited by "|". So that makes each records to be 2923 bytes long. I wanted to extract specific records like top 100 or 2500 - 5000, 50001 - 10000 etc. from this file. I tried using head command for top 100 records,... (1 Reply)
Discussion started by: acheepi
1 Replies
Login or Register to Ask a Question