How to add missing date and time in a bash script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to add missing date and time in a bash script?
# 8  
Old 01-13-2016
That version should provide the %(...)T format specifier. Did your copy/paste the proposal as given?
# 9  
Old 01-13-2016
yes, but i'm still getting the same error. Please see debug mode details below:

Code:
+ for DT in '{0..7200..60}'
+ printf '%(%F %H:%M)T 0\n' 1452611280
test.sh: line 7: printf: `(': invalid format character
+ for DT in '{0..7200..60}'
+ printf '%(%F %H:%M)T 0\n' 1452611220
test.sh: line 7: printf: `(': invalid format character
+ for DT in '{0..7200..60}'
+ printf '%(%F %H:%M)T 0\n' 1452611160
test.sh: line 7: printf: `(': invalid format character
+ for DT in '{0..7200..60}'
+ printf '%(%F %H:%M)T 0\n' 1452611100
test.sh: line 7: printf: `(': invalid format character

# 10  
Old 01-14-2016
Too bad ... what's said in man bash?

---------- Post updated at 10:20 ---------- Previous update was at 10:15 ----------

Well, try
Code:
read FD <file
FS=$(date -d"${FD% *}" +%s)
seq -f"@%.0f" $FS -60 $((FS-7200)) | date -f- +"%F %H:%M 0" | awk '
NR == FNR       {T[$1,$2] = $3
                 next
                }
($1,$2) in T    {$3 = T[$1,$2]
                 delete T[$1,$2]
                }
1
END             {for (t in T) print t, T[t]
                }
' SUBSEP=" " file -
2016-01-13 01:33 10
2016-01-13 01:32 0
2016-01-13 01:31 10
2016-01-13 01:30 10
2016-01-13 01:29 10
2016-01-13 01:28 10
2016-01-13 01:27 10
2016-01-13 01:26 10
2016-01-13 01:25 0
2016-01-13 01:24 0
2016-01-13 01:23 0
.
.
.
2016-01-12 23:34 0
2016-01-12 23:33 0
2016-01-12 21:33 10

These 2 Users Gave Thanks to RudiC For This Post:
# 11  
Old 01-14-2016
Hi RudiC,

thanks for the info. but this is what i am getting, it replaces all those in third column with 0.

Code:
2016-01-13 01:33 0
2016-01-13 01:32 0
2016-01-13 01:31 0
2016-01-13 01:30 0
2016-01-13 01:29 0
2016-01-13 01:28 0
2016-01-13 01:27 0
2016-01-13 01:26 0
2016-01-13 01:25 0
2016-01-13 01:24 0
2016-01-13 01:23 0
2016-01-13 01:22 0
2016-01-13 01:21 0
2016-01-13 01:20 0
2016-01-13 01:19 0
2016-01-13 01:18 0
2016-01-13 01:17 0
2016-01-13 01:16 0
2016-01-13 01:15 0
2016-01-13 01:14 0
2016-01-13 01:13 0
2016-01-13 01:12 0
2016-01-13 01:11 0
2016-01-13 01:10 0
2016-01-13 01:09 0
2016-01-13 01:08 0
2016-01-13 01:07 0
2016-01-13 01:06 0
2016-01-13 01:05 0
2016-01-13 01:04 0
2016-01-13 01:03 0
2016-01-13 01:02 0
2016-01-13 01:01 0
2016-01-13 01:00 0
2016-01-13 00:59 0
2016-01-13 00:58 0
2016-01-13 00:57 0
2016-01-13 00:56 0
2016-01-13 00:55 0
2016-01-13 00:54 0
2016-01-13 00:53 0
2016-01-13 00:52 0
2016-01-13 00:51 0
2016-01-13 00:50 0
2016-01-13 00:49 0
2016-01-13 00:48 0
2016-01-13 00:47 0
2016-01-13 00:46 0
2016-01-13 00:45 0
2016-01-13 00:44 0
2016-01-13 00:43 0
2016-01-13 00:42 0
2016-01-13 00:41 0
2016-01-13 00:40 0
2016-01-13 00:39 0
2016-01-13 00:38 0
2016-01-13 00:37 0
2016-01-13 00:36 0
2016-01-13 00:35 0
2016-01-13 00:34 0
2016-01-13 00:33 0
2016-01-13 00:32 0
2016-01-13 00:31 0
2016-01-13 00:30 0
2016-01-13 00:29 0
2016-01-13 00:28 0
2016-01-13 00:27 0
2016-01-13 00:26 0
2016-01-13 00:25 0
2016-01-13 00:24 0
2016-01-13 00:23 0
2016-01-13 00:22 0
2016-01-13 00:21 0
2016-01-13 00:20 0
2016-01-13 00:19 0
2016-01-13 00:18 0
2016-01-13 00:17 0
2016-01-13 00:16 0
2016-01-13 00:15 0
2016-01-13 00:14 0
2016-01-13 00:13 0
2016-01-13 00:12 0
2016-01-13 00:11 0
2016-01-13 00:10 0
2016-01-13 00:09 0
2016-01-13 00:08 0
2016-01-13 00:07 0
2016-01-13 00:06 0
2016-01-13 00:05 0
2016-01-13 00:04 0
2016-01-13 00:03 0
2016-01-13 00:02 0
2016-01-13 00:01 0
2016-01-13 00:00 0
2016-01-12 23:59 0
2016-01-12 23:58 0
2016-01-12 23:57 0
2016-01-12 23:56 0
2016-01-12 23:55 0
2016-01-12 23:54 0
2016-01-12 23:53 0
2016-01-12 23:52 0
2016-01-12 23:51 0
2016-01-12 23:50 0
2016-01-12 23:49 0
2016-01-12 23:48 0
2016-01-12 23:47 0
2016-01-12 23:46 0
2016-01-12 23:45 0
2016-01-12 23:44 0
2016-01-12 23:43 0
2016-01-12 23:42 0
2016-01-12 23:41 0
2016-01-12 23:40 0
2016-01-12 23:39 0
2016-01-12 23:38 0
2016-01-12 23:37 0
2016-01-12 23:36 0
2016-01-12 23:35 0
2016-01-12 23:34 0

is there a way for it to insert only those records that are not in the input file?

Thanks

---------- Post updated at 07:43 AM ---------- Previous update was at 07:40 AM ----------

sorry for asking too much.

Code:
seq -f"@%.0f" $FS -60 $((FS-7200)) | date -f- +"%F %H:%M 0"

this is the code that changes all value to "0"
# 12  
Old 01-14-2016
... which then is modified by the last (awk) step in the pipe ...
# 13  
Old 01-14-2016
Hi RudiC,

None, i have commented the awk part on the script. Please see details below.

SCIPT
Code:
[dev:Desktop]$ cat test.sh 
#!/bin/sh
read FD <test1.txt
FS=$(date -d "${FD% *}" +%s)

seq -f"@%.0f" $FS -60 $((FS-7200)) | date -f- +"%F %H:%M 0"  > ernie.txt
#awk 'NR == FNR {T[$1,$2] = $3
#                 next
#               }
#l
#END            { for (t in T) print t, T[t]
#               }
#' SUBSEP=" "

OUTPUT
Code:
[dev:Desktop]$ cat ernie.txt
2016-01-13 01:33 0
2016-01-13 01:32 0
2016-01-13 01:31 0
2016-01-13 01:30 0
2016-01-13 01:29 0
2016-01-13 01:28 0
2016-01-13 01:27 0
2016-01-13 01:26 0
2016-01-13 01:25 0
2016-01-13 01:24 0
2016-01-13 01:23 0
2016-01-13 01:22 0
2016-01-13 01:21 0
2016-01-13 01:20 0
2016-01-13 01:19 0
2016-01-13 01:18 0
2016-01-13 01:17 0
2016-01-13 01:16 0
2016-01-13 01:15 0
2016-01-13 01:14 0
2016-01-13 01:13 0
2016-01-13 01:12 0
2016-01-13 01:11 0
2016-01-13 01:10 0
2016-01-13 01:09 0
2016-01-13 01:08 0
2016-01-13 01:07 0
2016-01-13 01:06 0
2016-01-13 01:05 0
2016-01-13 01:04 0
2016-01-13 01:03 0
2016-01-13 01:02 0
2016-01-13 01:01 0
2016-01-13 01:00 0
2016-01-13 00:59 0
2016-01-13 00:58 0
2016-01-13 00:57 0
2016-01-13 00:56 0
2016-01-13 00:55 0
2016-01-13 00:54 0
2016-01-13 00:53 0
2016-01-13 00:52 0
2016-01-13 00:51 0
2016-01-13 00:50 0
2016-01-13 00:49 0
2016-01-13 00:48 0
2016-01-13 00:47 0
2016-01-13 00:46 0
2016-01-13 00:45 0
2016-01-13 00:44 0
2016-01-13 00:43 0
2016-01-13 00:42 0
2016-01-13 00:41 0
2016-01-13 00:40 0
2016-01-13 00:39 0
2016-01-13 00:38 0
2016-01-13 00:37 0
2016-01-13 00:36 0
2016-01-13 00:35 0
2016-01-13 00:34 0
2016-01-13 00:33 0
2016-01-13 00:32 0
2016-01-13 00:31 0
2016-01-13 00:30 0
2016-01-13 00:29 0
2016-01-13 00:28 0
2016-01-13 00:27 0
2016-01-13 00:26 0
2016-01-13 00:25 0
2016-01-13 00:24 0
2016-01-13 00:23 0
2016-01-13 00:22 0
2016-01-13 00:21 0
2016-01-13 00:20 0
2016-01-13 00:19 0
2016-01-13 00:18 0
2016-01-13 00:17 0
2016-01-13 00:16 0
2016-01-13 00:15 0
2016-01-13 00:14 0
2016-01-13 00:13 0
2016-01-13 00:12 0
2016-01-13 00:11 0
2016-01-13 00:10 0
2016-01-13 00:09 0
2016-01-13 00:08 0
2016-01-13 00:07 0
2016-01-13 00:06 0
2016-01-13 00:05 0
2016-01-13 00:04 0
2016-01-13 00:03 0
2016-01-13 00:02 0
2016-01-13 00:01 0
2016-01-13 00:00 0
2016-01-12 23:59 0
2016-01-12 23:58 0
2016-01-12 23:57 0
2016-01-12 23:56 0
2016-01-12 23:55 0
2016-01-12 23:54 0
2016-01-12 23:53 0
2016-01-12 23:52 0
2016-01-12 23:51 0
2016-01-12 23:50 0
2016-01-12 23:49 0
2016-01-12 23:48 0
2016-01-12 23:47 0
2016-01-12 23:46 0
2016-01-12 23:45 0
2016-01-12 23:44 0
2016-01-12 23:43 0
2016-01-12 23:42 0
2016-01-12 23:41 0
2016-01-12 23:40 0
2016-01-12 23:39 0
2016-01-12 23:38 0
2016-01-12 23:37 0
2016-01-12 23:36 0
2016-01-12 23:35 0
2016-01-12 23:34 0
2016-01-12 23:33 0

# 14  
Old 01-14-2016
So - why THIS question, then
Quote:
Originally Posted by ernesto
.
.
.
is there a way for it to insert only those records that are not in the input file?
.
.
.
?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Find gaps in time data and replace missing time value and column 2 value by interpolation in awk

Dear all, I am kindly seeking assistance on the following issue. I am working with data that is sampled every 0.05 hours (that is 3 minutes intervals) here is a sample data from the file 5.00000 15.5030 5.05000 15.6680 5.10000 16.0100 5.15000 16.3450 5.20000 16.7120 5.25000... (4 Replies)
Discussion started by: malandisa
4 Replies

2. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

3. Shell Programming and Scripting

Simple date and time calulation in BASH

There is a closed Thread: <url>Here will be the url to the original post once I have 5 posts in this forum...</url> But a small bug had found his way into this very cool and simple code. #!/bin/bash date2stamp () { date --utc --date "$1" +%s } stamp2date (){ date --utc --date... (2 Replies)
Discussion started by: frood
2 Replies

4. Shell Programming and Scripting

date time stamps in bash

I'm looking for a way to have the "date" command output the date in a specific format. I'm not familiar with the different ways to use the date command at all. i read up on it, but i dont get how to manipulate it. i know that i can get the date format to give me a format like: 2012-10-13... (6 Replies)
Discussion started by: SkySmart
6 Replies

5. Shell Programming and Scripting

Converting date/time and generating offsets in bash script

Hi all, I need a script to do some date/time conversion. It should take as an input a particular time. It should then generates a series of offsets, in both hour:minute form and number of milliseconds elapsed. For 03:00, for example, it should give back 04:02:07 (3727000ms*) 05:04:14... (2 Replies)
Discussion started by: emdan
2 Replies

6. Shell Programming and Scripting

add up time with xx:yy format in bash how?

Hi, How can I add up a series of string like: and get a total as hour and minutes in a format like this: (3 Replies)
Discussion started by: bashily
3 Replies

7. Shell Programming and Scripting

Bash script - im missing something and cant's figure out what

I just put together a script for work that will essentially automate the migration of our Windows fileserver to my newly created Debian based SAMBA server. My script will create the necessary directories then copy the data over to my new server, after that it will set the ACL's by using... (3 Replies)
Discussion started by: binary-ninja
3 Replies

8. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

9. Shell Programming and Scripting

Bash script error: missing destination file name operand.

Ok, i've been messing around in debian the past few days, setting up programs like subversion, mysql and logrotate. The purpose of this script is to use subversion to backup the binary logs. It runs in the cron every 2 hours or so (although I can't get my script to run properly atm, which is why... (1 Reply)
Discussion started by: cganly
1 Replies

10. Tips and Tutorials

Simple date and time calulation in BASH

The GNU date command in full of goodies but not when it comes to calculate a date or time difference. Here is what I came up with after looking to more than one solution. Code should be self explaining. #!/bin/bash date2stamp () { date --utc --date "$1" +%s } stamp2date (){ ... (0 Replies)
Discussion started by: ripat
0 Replies
Login or Register to Ask a Question