LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-10-2015, 10:30 AM   #16
Abdelrahman.fathy
LQ Newbie
 
Registered: Nov 2015
Posts: 19

Original Poster
Rep: Reputation: Disabled

Grail if you are talking about strftime and UTC flag ,I cannot confirm if it did work. I will check it and let you know
 
Old 11-11-2015, 02:30 AM   #17
Abdelrahman.fathy
LQ Newbie
 
Registered: Nov 2015
Posts: 19

Original Poster
Rep: Reputation: Disabled
grail;
i've used this function and it's doing the job

Code:
function ConvAST_To_GMT(timestamp)
{
	c="date -ud "timestamp;
	out=c|getline;
	close(c);
	return $0;
	
}
and i call it using IT="@" InFields[9] this as argument
where InFields[9] is the timestamp output from mktime


Another question is i have time like hh:mm
i want to concatenate 00 as ss
so that i can send the output to mktime
i tried this
DenyTimePart=OutDenials[11] "" ":" "00";
and so many other variation but none of them did the job
 
Old 11-11-2015, 03:39 AM   #18
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
So here is the simple line I used to convert to UTC:
Code:
echo 'OUT IamFeatureName 2013.11 9 IamUserName IamHostName "" 20 20 0 1cc 1cc 2af0 "" "" "" 07/15 13:27:12' | awk '{dspec = "2015"FS$17FS$18; NF=16;print $0,strftime("a %b %e %H:%M:%S %Z %Y",mktime(gensub(/[:/]/," ","g",dspec)),1),dspec}'
As for appending '00', I would need more information on why you think it does not work? I do see a needless pair of quotes after the array, but would not see these causing any issue.
 
1 members found this post helpful.
Old 11-11-2015, 03:44 AM   #19
Abdelrahman.fathy
LQ Newbie
 
Registered: Nov 2015
Posts: 19

Original Poster
Rep: Reputation: Disabled
thanks for the response but these needless pair of qoutes are needed for forcing awk to convert number to string so i can right pad with two zeros in place of seconds ofcousrse with space between them
for example if i have 10:15 as OutDenials[11]

i need output like 10 15 00
 
Old 11-11-2015, 03:52 AM   #20
Abdelrahman.fathy
LQ Newbie
 
Registered: Nov 2015
Posts: 19

Original Poster
Rep: Reputation: Disabled
also your line that you posted produces an error:
awk: fatal: 3 is invalid as number of arguments for strftime
maybe it's the awk version(i've GNU Awk 3.1.5) or something else
 
Old 11-11-2015, 05:02 AM   #21
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Well i see no reference to say it is a new feature to include the utc-flag, but maybe, my version is 4.1.3

As for the concatenation, I am not sure I follow, the below simple test seems to work just fine:
Code:
echo "10:57" | awk '{print $0":00"}'
No additional sets of quotes needed
 
Old 11-11-2015, 10:11 PM   #22
Abdelrahman.fathy
LQ Newbie
 
Registered: Nov 2015
Posts: 19

Original Poster
Rep: Reputation: Disabled
grail,
I'm sorry to bother you too much but can you look at the output , i've exactly used your statment:
Code:
{print $0":00"}


:00Y Blah_check 1.0 trudy DellHd-77 "" 1 -18 1 07/15 13:27


I mean the keyword Deny in the start have been overwritten
 
Old 11-11-2015, 10:32 PM   #23
Abdelrahman.fathy
LQ Newbie
 
Registered: Nov 2015
Posts: 19

Original Poster
Rep: Reputation: Disabled
Grail, it's ok i find my problem,
It's the difference between MSFT(Microsoft) and linux
i guess there was some non printable or some control character difference , so i used dos2unix and convert it and now your code is running fine.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to match different records based on multiple Field values using awk Abdelrahman.fathy Programming 4 11-04-2015 10:49 PM
Awk - Process a set of records if field $5 of line 01 is 'W', otherwise copy set to o High-T Linux - Newbie 6 02-06-2015 10:14 AM
[SOLVED] Idelete a row based on a mulitple field match white.horse Linux - Newbie 8 09-27-2012 03:33 PM
[SOLVED] Need help with awk and two csv: field match / substitution archduke83 Linux - Newbie 9 04-27-2012 11:49 AM
Equivalence classes, based on field values and multi-key hashtable openSauce Programming 5 05-16-2010 08:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration