Visit Our UNIX and Linux User Community


awk system date with -d option


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk system date with -d option
# 1  
Old 01-05-2008
awk system date with -d option

Hi

I get problems when using the following command :

Code:
cat logs | awk -F";" '{ system("date -d "1970-01-01 UTC+0100 $1 seconds""); }'
date: date invalide `1968641199401200'
date: date invalide `1968641199381709'

this is what i have in my log file :

Code:
cat logs
1199401200;a
1199381709;b

I don't know where this 196864 comes form

Any idea ?

Thx

Last edited by arag0rn; 01-05-2008 at 12:48 PM..
# 2  
Old 01-05-2008
Code:
while IFS=";" read a b
do
    date -d "1970-01-01 UTC+0100 $a seconds"
done  < file

# 3  
Old 01-05-2008
Thanx but This is not what i want to do

thx for this idea but it does not work for me Smilie
I made something that gives the same output your code should give but this is not what i am searching for :

Code:
for mytimestamp in $(cat logs| awk -F";" '{ print $1; }'); do echo $(date -d “1970-01-01 UTC+0100 $mytimestamp seconds”); done

What i want is to replace all the timestamps (first field) in a log file with the date in UTC+0100 format but i want to keep the other fields (file scheme)...

Last edited by arag0rn; 01-05-2008 at 12:49 PM..
# 4  
Old 01-05-2008
If you have GAWK you can use the strftime function or you can fit the script of gostdog74 like:

Code:
while IFS=";" read a b
do
    echo $(date -d "1970-01-01 UTC+0100 $a seconds")";"$b
done  < file

Regards

Previous Thread | Next Thread
Test Your Knowledge in Computers #150
Difficulty: Easy
Oracle discontinued OpenSolaris after their acquisition of Sun Microsystems.
True or False?

10 More Discussions You Might Find Interesting

1. Answers to Frequently Asked Questions

Compare date in .txt with system date and remove if it's lesser than system date

I m working on shell scripting and I m stuck where in my .txt file there is column as expiry date and I need to compare that date with system date and need to remove all the rows where expiry date is less than system date and create a new .txt with update. (1 Reply)
Discussion started by: Stuti
1 Replies

2. UNIX for Beginners Questions & Answers

Compare date in .txt with system date and remove if it's lesser than system date

Can someone help me with the code wherein there is a file f1.txt with different column and 34 column have expiry date and I need to get that and compare with system date and if expiry date is <system date remove those rows and other rows should be moved to new file f2.txt . I don't want to delete... (2 Replies)
Discussion started by: Stuti
2 Replies

3. HP-UX

awk command in hp UNIX subtract 30 days automatically from current date without date illegal option

current date command runs well awk -v t="$(date +%Y-%m-%d)" -F "'" '$1 < t' myname.dat subtract 30 days fails awk -v t="$(date --date="-30days" +%Y-%m-%d)" -F "'" '$1 < t' myname.dat awk command in hp unix subtract 30 days automatically from current date without date illegal option error... (20 Replies)
Discussion started by: kmarcus
20 Replies

4. UNIX for Dummies Questions & Answers

date command option e Help needed please!!

Hi All, I was trying to get the date in format "Feb2" I tried option "e" giving me a padded space and getting the result as "Feb 2". Though its working fine for dates 10 to 31. Please suggest me how to get rid of this space before date. Thanks Olivia (4 Replies)
Discussion started by: Olivia
4 Replies

5. Shell Programming and Scripting

csv file field needs to be changed current system date with awk

HI, I have csv file with records as shown below. 4102,Bangalore,G10,21,08/17/2011 09:28:33:188,99,08/17/2011 09:27:33:881,08/17/2011... (1 Reply)
Discussion started by: raghavendra.nsn
1 Replies

6. Solaris

Shutdown system option

I am working on sunos solaris. I want to know which is good for system shut-down ? (3 Replies)
Discussion started by: Jitesh Varshney
3 Replies

7. Shell Programming and Scripting

Advice on using awk in ksh with system date

OK I have a simple awk script: $ awk '/03\/11\/10/' foofile|awk -f finderrors.awk I want to use in the ksh script to so that I can do something like this: #!/bin/ksh TODAY=`date +"%D"` awk /$TODAY/ foofile|awk -f finderrors.awk The problem I am having is (I believe) is with the special... (3 Replies)
Discussion started by: bike4life
3 Replies

8. Solaris

date -d illegal option in Solaris

Hi All, Is it possible to run date -d option in Solaris? Do we have a work around so that -d option will be recognized by solaris as it is recognized by linux. I need this since i am using this in scripting and it works in Linux box. my problem is it doesn't work in solaris box. ... (6 Replies)
Discussion started by: linuxgeek
6 Replies

9. UNIX for Dummies Questions & Answers

Use of system date in awk

i'm facing problems in using system date in a awk script... it should display the date in a report in mm/dd/yy format.. please help me in this case.. thanks (3 Replies)
Discussion started by: Manish4
3 Replies

10. UNIX for Dummies Questions & Answers

using system date in awk

hi, I'm getting some issues while running below awk:- I want to use the system date to get pritned on the report but not getting it please help in this case BEGIN { sysdate = substr($date,5,6) print "WEA\t\t\t\t\t\t\t\t\t\tCLAIM AND APPROVAL REPORT" print "REPORT RUN DATE:",$sysdate... (1 Reply)
Discussion started by: Manish4
1 Replies

Featured Tech Videos