nawk time substracting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting nawk time substracting
# 1  
Old 10-26-2011
nawk time substracting

Nawk ‘BEGIN {printf “0t%d=Y\n”,srand () -1800}' | adb
I know that printf is printing the value in %d which is for a day of the month and subtracting the value by -1800 (30 minutes).
So if date is 14:25:45 subtracting from 1800 then time will equal to 13:55:45
I also know that srand () is function that is used to set a new seed for the random number generator.
However I don't know what is 0t doing? What is for?Is | adb - debugging the code?
Also what I want is to store the workout value in variable (so every time I run the script it subtracts 30 minutes from current time and stores the value in variable). So I can use the variable in loop which will check all the logs created 30 minutes ago. I can't use gawk
Any help will be greatly appreciated
Thank you all
# 2  
Old 10-26-2011
not sure why you're relying on awk's srand() function getting the current epoch time, but...
Code:
# here's my current EPOCH time
currentEpoch=$(/usr/bin/truss /usr/bin/date 2>&1 | /usr/bin/awk '/^time/ {print $NF}')

# here we convert EPOCH back to human readable format
back2Human=$(echo "0t${currentEpoch}=Y" | /usr/bin/adb)

subtracting '1800' from 'currentEpoch' will get you an epoch time of back 30 minutes from current.
This is all somewhat Solaris specific and may not be portable. There's a 'date/time' arithmetic in the FAQ section that you might find useful.
This User Gave Thanks to vgersh99 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

2. Shell Programming and Scripting

Adding or substracting from a Matrix column

Hello! I'm new to linux programming. It would be great if you could help me out. I have a matrix of kind: 10 30.0 20 190.5 40 180. 50 320.5 I would like to substract 180 from column 2 If the value is >180 to add 180 for column 2 If the value is <180 nothing if it is equal to... (3 Replies)
Discussion started by: lovelinux
3 Replies

3. Shell Programming and Scripting

Using awk or nawk to convert epoch time to date format

Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do. What am I trying to do? I need to take the time value in epoch format returned from the... (5 Replies)
Discussion started by: minigts
5 Replies

4. Shell Programming and Scripting

Substracting days from current date(K shell script)

Hi, I want to subtract 'n' days from the current timestamp in a k shell script. Is there any inbuilt function to do it or any workaround solution to get the date. And I want the output to be in YYYY:MM:DD HH:MM:SS format. Please help. Thanks in advance. (4 Replies)
Discussion started by: Suryaaravindh
4 Replies

5. Shell Programming and Scripting

time conversion using nawk

hi, i've got an input file that contains 12345678 AAA 12345679 BBB 12345680 CCC where 1st column is epoch time while the second column are some string. I'm using nawk to do regular expression on the 2nd column and i need to convert the epoch time to human readable time e.g. 'yyyymmdd... (5 Replies)
Discussion started by: bing
5 Replies

6. Shell Programming and Scripting

Nesting - two nawk into one nawk

hi people; this is my two awk code: nawk '/cell+-/{r=(NF==8) ? $4FS$5FS$6 : NF==7 ? $4FS$5 : $4 ;c=split(r,rr);for (i=1;i<=c;i++){if(rr != "111111"){printf($3" %d ""\n",(i+3))}}printf("")}' /home/gc_sw/str.txt > /home/gc_sw/predwn.txt nawk -F'*' '{gsub(/ *$/,"")}$0=$1$($NF-2)'... (2 Replies)
Discussion started by: gc_sw
2 Replies

7. AIX

Substracting time between two columns

I've start and end time in two columns. How can I substract time from column 2 and column 1 and receive output in another file 'd' ? Code: $ cat c 12:55:04 2:03:56 2:03:56 3:20:17 14:00:00 13:05:00 (1 Reply)
Discussion started by: alps0206
1 Replies

8. Shell Programming and Scripting

substracting common row names from two files

Hi, I have two files with with similar row names. For the names that match, I want to substract the values from each column. eg (files are tab separeted). FILE1: hhh 2 4 5 KKL 2 3 2 LLP 2 1 2 FILE2: hhh 3 1 1 KKL 2 1 1 UUI 1 1 1 (10 Replies)
Discussion started by: kylle345
10 Replies

9. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies

10. Shell Programming and Scripting

Nawk Time Function

Hi All, I am using solaris and nawk. Is there any time function in nawk which is simliar to the shell `date` function ? Can any experts show any examples? (4 Replies)
Discussion started by: Raynon
4 Replies
Login or Register to Ask a Question