Awk new datetime everyline


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk new datetime everyline
# 1  
Old 08-12-2010
Question Awk new datetime everyline

Hi,

I'm using awk in HP-UX machine which does not support systime(), strftime(). So to get the date time I was using :

Code:
 
seq 1 100000 | awk ' "date +%Y%m%d%H%M%s" | getline curtime; print curtime }'

However the above code gets the date only once, next time it is not updated. For example if I clear the curtime, like :

Code:
 
seq 1 100000 | awk ' "date +%Y%m%d%H%M%s" | getline curtime; print curtime; curtime = "" }'

It'll print the date only once and blanks for other lines.

Is there any way I can get the current date time for everyline?
# 2  
Old 08-12-2010
Try to close the date command instead of clearing the variable curtime, something like:
Code:
seq 1 100000 | awk '{"date +%Y%m%d%H%M%S" | getline curtime; print curtime; close("date +%Y%m%d%H%M%S")}'

# 3  
Old 08-16-2010
@Franklin52,
Thanks for replying to both of my queries in this forumSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

--Parsing out strings for repeating delimiters for everyline

Hello: I have some text output, on SunOS 5.11 platform using KSH: I am trying to parse out each string within the () for each line. I tried, as example: perl -lanF"" -e 'print "$F $F $F $F $F $F"' But for some reason, the output gets all garbled after the the first fields.... (8 Replies)
Discussion started by: gilgamesh
8 Replies

2. Shell Programming and Scripting

Filename with datetime

Hello All, I need unix command to generate a file with datetime in it. For example : ABC_YYYYMMDDHH24MISS.txt Regards Biswajeet Ghosh (1 Reply)
Discussion started by: bghosh
1 Replies

3. UNIX for Dummies Questions & Answers

Find files between two datetime..

Hi All, How do i find all the files between two times. Eg: 26 may 2014 06:00 to 26 may 2014 14:00 mmin and mtime gives for a specific period. we receive hundreds of files input directories and i need to find how many files are received between given specific datetime. Thanks. (2 Replies)
Discussion started by: abhi_123
2 Replies

4. Shell Programming and Scripting

How to append server name to everyline?

I am executing df -mP to see the disk utilization. I would like to append servername also to each and every line. df -mP | awk '{ print $1","$2","$3","$4","$5","$6 }' trying to add something like this df -mP | awk '{ print $1","$2","$3","$4","$5","$6","$hostname }' ... (1 Reply)
Discussion started by: lazydev
1 Replies

5. Shell Programming and Scripting

Help: Change date to datetime mysql using awk

#cat file1.log 10.51.61.38;Thu Nov 1 08:06:12 2012;Logout 10.51.62.21;Thu Nov 1 08:06:16 2012;Login output result: 10.51.61.38;2012-11-01 08:06:12;Logout 10.51.62.21;2012-11-01 08:06:16;Login how to write script using awk, need help (1 Reply)
Discussion started by: pillawa
1 Replies

6. Shell Programming and Scripting

How to compare datetime?

Hi, To get the batch status, I will need to check if the particular job started after 5PM. if the job start time is before 5 pm, then it means that the job has not started for this particular date. I will run the script with date as argument. For eg: BS 07/10/2012 Start time from the log is... (8 Replies)
Discussion started by: ajayakunuri
8 Replies

7. Shell Programming and Scripting

datetime difference in seconds

Hi, I'm trying to find processing time of my script. Please can someone give me the commands to get the start/end time in "dd-mm-yyyy hh:mm:ss" and the differnce in seconds. Thanks! (5 Replies)
Discussion started by: dvah
5 Replies

8. Programming

SQL datetime calculation

Suppose I have a mysql table consisting of measurements taken during irregular intervals as follows: CREATE TABLE data (datetime DATETIME, value INTEGER); mysql> SELECT datetime, value FROM data; +---------------------+---------+ | datetime | value |... (2 Replies)
Discussion started by: figaro
2 Replies

9. Shell Programming and Scripting

datetime.pm

Hi, I'm trying to use datetime.pm function in Perl. I do not have in the library. Is there a way to get it and put it into library? Thanks, George. (1 Reply)
Discussion started by: gpaulose
1 Replies

10. Shell Programming and Scripting

cut columns in everyline

Is there a betterway to cut certain columns in everyline based on positions. Basically, I have a largefile and eachline is of 1000 characters and I need to cut the characters 17-30, 750-775, 776-779, 780-805 while do fptr=`cat $tempfile | head -$i | tail -1` ... (4 Replies)
Discussion started by: gunaah
4 Replies
Login or Register to Ask a Question