Separate date timestamp use awk or sed command ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Separate date timestamp use awk or sed command ?
# 1  
Old 07-27-2009
Question Separate date timestamp use awk or sed command ?

Hi,

I have logfile like this :

Quote:
20090513123415
20090719140136
20090712092340
20090725074955
20090725074956
20090725074955
20090725074957
20090719105625
20090712092340
20090712092340
20090724191130
20090719110932
20090712092340
20090725133551
20090719122639
20090712092340
20090725142250
20090724223147
20090719114652
Actually the format is date format :
yyyymmddHHMMSS

and i want the log become this format
yyyy-mm-dd HH:MM:SS

for example
2009-07-19 11:46:52

Can somebody help me ?
Thanks in advance

Last edited by justbow; 07-27-2009 at 02:03 AM.. Reason: change
# 2  
Old 07-27-2009
try..
Code:
awk '{print substr($1,1,4)"-"substr($1,5,2)"-"substr($1,7,2),substr($1,9,2)":"substr($1,11,2)":"substr($1,13,2)}' file

# 3  
Old 07-27-2009
Quote:
Originally Posted by justbow
...
Actually the format is date format :
yyyymmddHHMMSS

and i want the log become this format
yyyy-mm-dd HH:MM:SS

for example
2009-07-19 11:46:52
...
One way to do it in perl:

Code:
$ 
$ perl -ne '@x=unpack("A4 A2 A2 A2 A2 A2",$_); printf("%s-%s-%s %s:%s:%s\n",$x[0],$x[1],$x[2],$x[3],$x[4],$x[5])' logfile.txt
2009-05-13 12:34:15
2009-07-19 14:01:36
2009-07-12 09:23:40
2009-07-25 07:49:55
2009-07-25 07:49:56
2009-07-25 07:49:55
2009-07-25 07:49:57
2009-07-19 10:56:25
2009-07-12 09:23:40
2009-07-12 09:23:40
2009-07-24 19:11:30
2009-07-19 11:09:32
2009-07-12 09:23:40
2009-07-25 13:35:51
2009-07-19 12:26:39
2009-07-12 09:23:40
2009-07-25 14:22:50
2009-07-24 22:31:47
2009-07-19 11:46:52
$

tyler_durden
# 4  
Old 07-27-2009
sed line will be shorter:
Code:
sed 's/\(....\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1-\2-\3 \4:\5:\6/' logfile.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sed/awk command to convert number occurances into date format and club a set of lines

Hi, I have been stuck in this requirement where my file contains the below format. 20150812170500846959990854-25383-8.0.0 "ABC Report" hp96880 "4952" 20150812170501846959990854-25383-8.0.0 End of run 20150812060132846959990854-20495-8.0.0 "XYZ Report" vg76452 "1006962188"... (6 Replies)
Discussion started by: Chinmaya Kabi
6 Replies

2. Shell Programming and Scripting

Help awk/sed: putting a space after numbers:to separate number and characters.

Hi Experts, How to sepearate the list digit with letters : with a space from where the letters begins, or other words from where the digits ended. file 52087mo(enbatl) 52049mo(enbatl) 52085mo(enbatl) 25051mo(enbatl) The output should be looks like: 52087 mo(enbatl) 52049... (10 Replies)
Discussion started by: rveri
10 Replies

3. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

4. Shell Programming and Scripting

awk/sed script to print each line to a separate named file

I have a large 3479 line .csv file, the content of which looks likes this: 1;0;177;170;Guadeloupe;x 2;127;171;179;Antigua and Barbuda;x 3;170;144;2;Umpqua;x 4;170;126;162;Coos Bay;x ... 1205;46;2;244;Unmak Island;x 1206;47;2;248;Yunaska Island;x 1207;0;2;240;north sea;x... (5 Replies)
Discussion started by: kalelovil
5 Replies

5. Shell Programming and Scripting

Fix timestamp with Sed or Awk

Hi I am dealing with the following string: Date: Thur, 13 March 2011 01:01:10 +0000 I asked for help in another topic that converted a similar string: Date: Thur, 13 March 2011 9:50 AM To a 24 hr standard. The problem is that it comes out as: Date: Thur, 13 March 2011 9:50:00 +0000... (4 Replies)
Discussion started by: duonut
4 Replies

6. Shell Programming and Scripting

Concatenating lines of separate files using awk or sed

For example: File 1: abc def ghi jkl mno pqr File 2: stu vwx yza bcd efg hij klm nop qrs I want the reult to be: abc def ghistu vwx yza jkl mno pqrbcd efg hij klm nop qrs (4 Replies)
Discussion started by: tamahomekarasu
4 Replies

7. Shell Programming and Scripting

awk command to separate a field

I have a log file that I am trying to convert. File contents something like this: aaaaa bbbbbb cccc dddddd\123 eeeee ffffffff I am trying to output the fields in a different order and separate field 4 so that the "123" and "dddddd" can be output separately. for example bbbbbb aaaaa 123... (5 Replies)
Discussion started by: jake1988
5 Replies

8. UNIX for Advanced & Expert Users

AIX/awk date to unix timestamp

Hello, I am inside a awk script on AIX, I am feeding to awk ls -luNR i need to convert ls -u time format "month day h:m/yr" to Unix epoch time, POSIX time, or aka unix timestamp I do not have strftime funk in my awk, and i have to do this fast meaning that I cannot do a system call in the... (1 Reply)
Discussion started by: nullwhat
1 Replies

9. Linux

SED/AWK Script to clear log file using timestamp?

I have a log file on our system which fills up with lines that have been timestamped, as follows.... 03/03/2008 10:56:06:815] (ERROR) balance: continuing session to genapp02 : 18500 03/03/2008 10:56:06:820] (ERROR) balance: continuing session to genapp02 : 18500 03/03/2008 10:56:07:003]... (2 Replies)
Discussion started by: davesimm
2 Replies

10. UNIX for Advanced & Expert Users

Deleting timestamp using sed command

Hi, I'm trying to compare Actual.html with a baseline.html However, everytime it fails b'coz of the timestamp differences between the two. So, thought of stripping off the timestamp from both the *html files before comparing using below sed command over Solaris Unix platform:... (3 Replies)
Discussion started by: elearn.latha
3 Replies
Login or Register to Ask a Question