Tag Info

New answers tagged

1

This came up when using date -d "$death_date - $y years - $m months - $d days" to get a birth date (for genealogy). That command is WRONG. Months aren't all the same length, so (date + offset) - offset != date. Ages, in year/month/day, are measures going forwards from the date of birth. $ date --utc -d 'mar 28 1867 +72years +11months +2days' Fri Mar 1 ...


1

You could use sed: sed "s/yyyymmdd/$(date '+%Y%m%d')/g" abc.fil That replaces the string yyyymmdd with the current date formatted as desired. Edit: If yyyymmdd is just the format of the date you want to replace, then use that command (assumes GNU sed): sed -r "s/[12][0-9]{3}[01][0-9][0-3][0-9]/$(date '+%Y%m%d')/g" abc.fil The long regular expression ...


1

> today=$(date +%Y%m%d) > sed "s/yyyymmdd/${today}/g" abc.fil o/p: 20150127.xyz.doc 20150127.mno.dat abc.txt


-1

try cat abc.fil | sed s/yyyymmdd/`date +%Y%m%d`/


1

This will get you started. Requires GNU awk for the time functions: gawk -F, ' function totime(ymd) {gsub(/[-_]/," ",ymd); return mktime(ymd " 0 0 0")} BEGIN {now = systime(); m1 = now - 86400 * 30; m6 = now - 86400 * 180} FNR == 1 {next} {t = totime($3)} t > m1 {print "m1", $0; next} t > m6 {print "m6", $0} ' file m6 ...


0

Just play with date command inside awk and redirect output from print to desired files according to certain conditions: awk -F, 'BEGIN{ "date -d\"month ago\" +%s" | getline T1; close("date"); "date -d\"6 months ago\" +%s" | getline T6; close("date")} { "date -d" $3 " +%s" | getline t; close("date"); if(t>T1){print $0>"file2";next} ...


0

Doing "ls -otr --time-style=+%Y%m%d%H%M.%S" will get the date in the proper format, though with a bunch of other info that's easily edited out. This is handy when assigned to an alias, and the output redirected to a file.


2

stat -f %m -t %Y%m%d%H%M.%S myfile This prints the timestamp in the format required for touch -t. Beware that the timestamp is expressed in the local timezone, which could be awkward to port files between timezones or for timestamps during the repeated hour of the summer-to-winter switch in timezones with DST. To avoid timezone trouble, use the UTC ...


4

You may convert the time returned by stat or perl to the format you want with the command date (assuming you have GNU coreutils installed): # Convert UNIX time returned by perl to year+month+day $ date -d @$(perl -le 'print((stat shift)[9])' FILENAME) +%Y%m%d 20130703 # Convert formatted time returned by GNU stat to year+month+day $ date -d "$(stat -c %y ...


0

It could look like this: #!/bin/bash # 1. change directory cd "/mnt/harddrive/BASE/" # 2. prompt for name of file or directory echo -n "file or directory name: " # ... and read it read HANDLE # 2. b - check if it exists and is readable if [ ! -r "$HANDLE" ] then echo "$HANDLE is not readable"; # if not, exit with an exit code != 0 exit 2; ...


1

If you add a one (1) after the hyphen (-) it works on Linux and is also portable to HP-UX (and possibly other flavors of UNIX): $ date +'%Y%-1m%d' 2015120


22

With GNU, FreeBSD or OS/X date (or date implementations that use the system's libc's strftime() where that is the GNU libc), adding hyphen - after % prevents numeric fields from being padded with zeroes: $ date +'%Y%-m%d' 2015120 From man date on a GNU system: By default, date pads numeric fields with zeroes. The following optional flags may ...


3

> date +'%Y %m %d' | ( read year month day; echo "${year}${month#0}${day}" ) 2015120


0

This used to be quite simple, all you had to do was edit the relevant gnome-shell js file: /usr/share/gnome-shell/js/ui/dateMenu.js and change date/time format. As of v. 3.12 this is no longer a trivial task as shell js files come as a binary file and on top of that, the panel date/time code was moved to gnome-desktop. As a result, the date format is now ...


0

Assuming you input text is like this: 1232,abdc, 02-Jan-2014 18:01:37</br> 4534,kdafh, 20-Feb-2014 07:17:19</br> 364,asjhdk, 11-Jul-2012 23:20:30</br> my answer would become: cat input-file.txt | sed 's[</br>[[g' | awk -F ',' '{printf("%s,%s,",$1,$2);system("date -d \""$3" "$4"\" +\"%Y-%m-%d %H:%M:%S\"");}' > output-file.txt ...


0

Looking for same answer I found this old topic And I solved it by using grep with -B option: cat /var/log/mylogs.log | grep -B 1000 "Jul 20 15:00:00" It will show line with that date and 1000 lines before it. Simple and easy. You just need to be sure that you are greping date that exist in your log file. Same way with -A option you can search for newer ...


1

One possible answer using awk, assuming the input file is input-file.txt and output file is output-file.txt : awk -F ',' '{printf("%s,%s,",$1,$2);system("date -d "$3" +%Y-%m-%d");}' input-file.txt > output-file.txt



Top 50 recent answers are included