Tag Info

New answers tagged

0

On Mac OS X using the FreeBSD date command you could do the transformation via epoch time: epoch_time="$(LANG=C TZ='EST' date -j -f "%a %b %d %T %Z %Y" "Wed Dec 25 06:35:02 EST 2013" "+%s")" a="$(date -r $epoch_time '+%F') echo "$a" # 2013-12-25


1

On OpenWRT, date is busybox, which has limitations, but this is not strictly one of them. The underlying problem is that libc (uClibc) does not support this GNU strftime extension. You should have lua by default, but that won't help without some other non-default modules. hwclock calls gettimeofday() for comparing/setting the RTC (hardware clock), but it ...


0

You should be able to view the system clock time zone by catting this file: /etc/sysconfig/clock.


3

Try unsetting the TZ variable (which is different from setting it to ""): $ (date; export TZ=/usr/share/zoneinfo/Canada/Eastern; date; unset TZ; date) Tue Nov 18 03:25:25 IST 2014 Mon Nov 17 16:55:25 EST 2014 Tue Nov 18 03:25:25 IST 2014 Note how I tried it in a subshell, so that my current shell remains unaffected.


0

Actually there is also a package called coreutils-date! Didn't know about it! There all standard functionality is included!


1

You are using strong quoting(single quoting) in the script as strong quoting prevents the interpretation of contents inside the single quote except the quote. Single quoting turns off the special meaning of $ in a script. #!/bin/bash echo "$PATH" Works! #!/bin/bash echo '$PATH' Not Works! Output remains same as input


1

You must use double quotes instead of single quote: date -d "14 Oct 1582 + $d days"


1

If you have a C compiler on it and can't find anything else, this will report, e.g. > millitime && sleep 1 && millitime 14/11/2014 9:39:49:364 14/11/2014 9:39:50:368 #include <errno.h> #include <stdio.h> #include <string.h> #include <sys/time.h> #include <time.h> int main (void) { struct timeval now; ...


3

Just store the value of date +%Y%m%d%H%M%S in a variable: x=$(date +%Y%m%d%H%M%S) and later on mv file1 file1_$x.txt mv file2 file2_$x.txt ... or in a loop for all *.txt files for file in *.txt; do echo mv "$file" "${file%.txt}"_$x.txt; done (remove echo if you are happy with what you see on the screen)


0

With perl: $ perl -MTime::Piece -anle ' $F[2] = Time::Piece->strptime($F[2],"%r")->strftime("%H:%M:%S"); push @out, [$F[2]."-".join("-", reverse(split("-",$F[0]))), join(" ",@F)]; END { print for map { $_->[1] } sort { $a->[0] cmp $b->[0] } @out; }' file 11-12-2014 - 00:08:03 lat = 41.937911; lon = ...


0

With python and the dateutil module (pip install dateutil), you can do the sorting directly on the datetime objects: #! /usr/bin/env python import sys from dateutil.parser import parse lines = [] for line in open(sys.argv[1]): d, rest = line[:24], line[24:] lines.append((parse(d), rest)) for x in sorted(lines): print x[0], x[1], start with ...


0

I would use awk with sort: awk '{while("date +%T -d" $3|getline x){$3=x}}1' logfile | sort -t- -n -k3 -k1 -k2 Lets first modify your log a little bit to have different dates: 11-12-2010 - 03:03:59AM lat = 41.990516; lon = -93.430704 11-12-1998 - 03:05:15AM lat = 41.001546; lon = -93.443352 11-12-2030 - 03:11:50AM lat = 42.039054; lon = -93.442001 ...


0

You can do this using the GNU date command. It can take strings and print out the corresponding date: $ date -d "11/11/2014 04:12:03PM" Tue Nov 11 16:12:03 CET 2014 Note, however, that it does not like DD-MM-YYY: $ date -d "11-11-2014" date: invalid date ‘11-11-2014’ So, first run a sed on your file to replace all - with /. Then, pass that through read ...


0

Your entire pipeline in awk without lots of unnecessary pipes. Similar to costas but without using any external commands. awk '/usb/{split($3,a,":");b[++x]=(a[1]*3600)+(a[2]*60)+a[3]}END{print b[x-1]-b[x]}' /var/log/kern.log Heres just the last bit with the dates worked out if you decide to keep the pipes awk ...


1

If you use awk you can do it in one invocation awk ' /usb/{ ("date +%s -d "$3)|getline t[++i]; } END{ print t[i-1]-t[i]; }' /var/log/kern.log


1

A more general solution because it works with times from different dates, too: echo "18:23:24 18:20:20" | (read later_time; read former_time; former_seconds=$(date --date="$former_time" +%s); later_seconds=$(date --date="$later_time" +%s); echo $((later_seconds-former_seconds)) ) 184


1

I would take a step further (inspired by this post): cat /var/log/kern.log |grep usb |tail -2| awk '{print $3}' | awk -F: '{ print ($1 * 3600) + ($2 * 60) + $3 }' # => 18:23:24 --> 66204 So, after I had: 66204 66020 You could then do: echo $((66204-66020)) # => 184


2

Check again the link you posted, there's a commit message: date: support parsing of ISO-8601-with-"T" dates It was implemented in coreutils 8.13 (see changelog).


1

I didn't find a simple solution to my question, so I've written a small Bash script to solve it. You need to download the leap seconds file given in the link below and put it with the script or change the path to it. I didn't write utc2unix.sh yet, but it's very easy to adapt. Do not hesitate to comment/give suggestions... unix2utc.sh: #!/bin/bash # ...


1

I don't want to do your homework for you, but this might point you in the right direction: #!/bin/sh date=`date +%D` echo "Date in MM/DD/YY:" echo $date newdate=`date -d $date +"%a %b %e %H:%M:%S %Z %Y"` echo "Date Expanded:" echo $newdate hash="$(echo -n "$newdate" | md5sum | awk '{print $1}')" echo "Hash of expanded date:" echo $hash You can create ...


0

Using a couple of scripting languages: perl -MDateTime -E 'say DateTime->now(time_zone => "local")->set_time_zone("Australia/Sydney")->strftime("%F %T %Z")' echo 'puts [clock format [clock seconds] -format {%Y-%m-%d %T %Z} -timezone ":Australia/Sydney"]' | tclsh


1

If you want to convert a random time from the local timezone to a time in another timezone: $ date -d @$(date +%s -d '2014/10/01 12:34:56') Wed Oct 1 12:34:56 CEST 2014 $ TZ=Australia/Sydney date -d @$(date +%s -d '2014/10/01 12:34:56') Wed Oct 1 20:34:56 EST 2014 I use seconds since the unix epoch as the natural way to communicate a point in time.


2

writing date as an argument to another command will not get you the output of that command, just the string you typed. In bash you can insert the result from a command by including it in $( ). That leaves that you need to specify form (format) that you want to get from date, and that can be deduced from man date (FORMAT section): date '+%Y-%m-%d %H:%M' ...


0

I advise you to not worry about changing a file's ctime, it's really not worth the hassle (as I discovered myself a month or two ago when writing a script to organize files for simple MP3 players). As well as the methods discussed in the SO question I linked to above, there is another straight-forward method: copy the file to a temporary name, delete the ...


3

The option was introduced in the coreutils date (which is probably what you have) in 1999 (Apr. 8). The documentation was removed in 2005 without much explanation in the commit. On 2011-10-27 the help for --iso-8601 was reintroduced with the following explanation: We deprecated and undocumented the --iso-8601 (-I) option mostly because date could not ...


1

If the file is directly under the path you are given (no extra subdirectories) then this should work. file=$path/StaticData_Sets_$(date +"%Y%m%d")-*.txt If there are then this should work (might need to manually enable globstar in bash). file=$path/**/StaticData_Sets_$(date +"%Y%m%d")-*.txt


1

That find command should find the file with todays date: find /path/ -regex ".*\/StaticData_Sets_$(date +%Y%m%d)-[0-9]+\.txt" It find all that contain /StaticData_Sets_, then the date in your desired format, and then a digit ([0-9]+).


6

Use command date to generate current day with proper output format, and append that string to file name in the following fashion: filename=StaticData_Sets_$(date +"%Y%m%d") find . -name "$filename*.txt"


0

You can use command substitution for this $ touch -t $(date +%m%d%H%M) file



Top 50 recent answers are included