How to split timestamp and put a dot between YYYYMMDD and HHMMSS?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to split timestamp and put a dot between YYYYMMDD and HHMMSS?
# 1  
Old 03-03-2017
How to split timestamp and put a dot between YYYYMMDD and HHMMSS?

I have a string
Code:
time=20170303201234

I want to split it and put a dot
result:
Code:
20170303.201234

CODE:
Code:
ttdotss=`echo ${time} | [0-9]{8}.[0-9]{8}`

Doesn't understand
I tried this:

CODE:
Code:
ttdotss=`echo ${time} |cut -c 1-8 | . | cut -c 9-14`

Result:
Code:
 script[69]: .: argument expected

Could you help me?

Thanks form contribution

Last edited by Scrutinizer; 03-03-2017 at 02:57 PM.. Reason: code tags
# 2  
Old 03-03-2017
Code:
echo '20170303201234' | sed 's/\(.*\)\(......\)/\1.\2/'

# 3  
Old 03-03-2017
sed:
Code:
echo "$time" | sed 's/......$/.&/'


If you have ksh93, or zsh, try:
Code:
printf "%.6f\n" "$(( time / 1000000.0 ))"



--
just for fun:
Code:
echo "$time" | fold -w8 | paste -d\. - -


Last edited by Scrutinizer; 03-03-2017 at 03:17 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 03-03-2017
https://www.unix.com/shell-programming-and-scripting/271296-how-split-timestamp-put-dot-between-yyyym

Found
Code:
Code:
 
 ttdotss=`echo ${time} |sed 's/.\{8\}/&./g'`

Result
Code:
 
 20170303.122334


Last edited by Scrutinizer; 03-03-2017 at 03:26 PM.. Reason: icode -> code tags
# 5  
Old 03-03-2017
Code:
echo ${time%??????}.${time#????????}
20170303.201234

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

How to put dot in timestap?

I have a string: Code time=20170303122334 I need the result: 20170303.122334 I did: CODE: ttdotss=`echo ${time} |sed 's\(.|{8\}\)/|1 /g'` Result sed: Function s\(.|{8\}\)/|1 /g cannot be parsed. Could you please help me to resolve this issue? Thanks for contribution (2 Replies)
Discussion started by: digioleg54
2 Replies

3. Shell Programming and Scripting

AIX : Need to convert UNIX Timestamp to normal timestamp

Hello , I am working on AIX. I have to convert Unix timestamp to normal timestamp. Below is the file. The Unix timestamp will always be preceded by EFFECTIVE_TIME as first field as shown and there could be multiple EFFECTIVE_TIME in the file : 3.txt Contents of... (6 Replies)
Discussion started by: rahul2662
6 Replies

4. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

5. Programming

How to put dot(.) in a string in C?

Hi all, Can anybody please tell me how can I put dot(.) in a string using C programming. for example -- I am having string "10111988" and I want to convert it as "10.11.1988" I will appriciate and thanks in advance.. (4 Replies)
Discussion started by: smartgupta
4 Replies

6. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

7. Shell Programming and Scripting

split input data file and put into same output file

Hi All, I have two input file and need to generate a CSV file. The existing report just "GREP" the records with the Header and Tailer records with the count of records. Now i need to split the data into 25 records each in the same CSV file. id_file (Input file ) 227050994 232510151... (4 Replies)
Discussion started by: rasmith
4 Replies

8. AIX

Convert time (YYYYMMDD HHMMSS) to UTC

Okay, so let's say we have a string like: 20110105_193345 This represents: January 5th, 2011 = 20110105 24-hour style time 19:33:45 = 193345 Okay, so we have our time. It's January 5th, 2011 at 19:33:45. I want to convert this time from Eastern Time Zone (which it currently is in)... (1 Reply)
Discussion started by: syndex
1 Replies

9. Solaris

Get timestamp by 'YYYYMMDD'

Hi, I'd like to get the file timestamp by 'YYYYMMDD' on Solaris 9 9/05. I can get it on the other UNIX distribution with the following command; ls -d -l --time-style='+%Y%m%d'$FNAME | awk '{print $6; }' but cannot get it on Solaris, it comes format error. Could you give me any advice on this? (18 Replies)
Discussion started by: elph
18 Replies

10. Shell Programming and Scripting

How to split a file into exactly two files by timestamp?

2009-10-29 03:39:11,720 INFO - Optimize cache for minimal puts: disabled 2009-10-29 03:39:11,720 INFO - Structured second-level cache entries: disabled 2009-10-29 03:39:22,687 WARN - Problem starting service jboss.web.deployment:war=dt-sp-fabric-delegate-ws-war-3.5.0.war,id=1483428821... (3 Replies)
Discussion started by: maheshshinde
3 Replies
Login or Register to Ask a Question