Visit Our UNIX and Linux User Community


Appending unix timestamp to every line of a statistical file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending unix timestamp to every line of a statistical file
# 1  
Old 11-17-2011
Question Appending unix timestamp to every line of a statistical file

I have a statistical file populating every minute as below:
Code:
2011-11-11-1108	1955	891
2011-11-11-1109	2270	1049
2011-11-11-1110	1930	904
2011-11-11-1111	2030	931
2011-11-11-1112	1944	900
2011-11-11-1113	1922	875

Instead of having the date and time in the given format (2011-11-11-1113) I would like it to view it as a unix timestamp in seconds based on seconds since standard epoch of 1/1/1970. Can anyone assist?Smilie


Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 11-17-2011 at 04:09 AM.. Reason: code tags
# 2  
Old 11-17-2011
You could either cut and multiply it with seconds yourself to get it or use some neat perl function like localtime - perldoc.perl.org
# 3  
Old 11-17-2011
Else try modify the code of the script which is populating the statistical file on minute basis with date timestamp ..

From
Code:
$ date +%Y-%m-%d-%H%M
2011-11-17-0720

To
Code:
$ nawk 'BEGIN{print srand()}'
1321514472

# 4  
Old 11-24-2011
I have no sufficient right to modify the script generating the statistics.

Can i have a way of appending the output of

Code:
$ nawk 'BEGIN{print srand()}'

as a new column of data in the file
# 5  
Old 11-24-2011
try this first to see if it works on yours:
Code:
 (export TZ=UTC;date -j -f %Y-%m-%d-%H%M%S   1970-01-01-000000)
Thu Jan  1 00:00:00 UTC 1970
 (export TZ=UTC;date -j -f %Y-%m-%d-%H%M%S +%s  1970-01-01-000000)
0


Last edited by bigearsbilly; 11-24-2011 at 07:28 AM.. Reason: tidy it up
# 6  
Old 11-24-2011
Code:
export TZ=UTC;date -j -f %Y-%m-%d-%H%M%S +%s  1970-01-01-000000

export: Command not found.
date: illegal option -- j
date: illegal option -- f
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
# 7  
Old 11-24-2011
The TZ setting can be quite awkward depending system which you say nothing of... Nor do you mention what shell you use...

Previous Thread | Next Thread
Test Your Knowledge in Computers #791
Difficulty: Easy
Logic gates cannot be used to store data.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash - Appending to specific line in file

I'm working on a personal project, a multiplication quiz script for my kids. In it, the user's performance will be recorded and written to a file. After they've played it a little while, it will start to focus more on the ones that give them the most trouble-- that take a long time to answer or... (4 Replies)
Discussion started by: treesloth
4 Replies

2. Shell Programming and Scripting

Appending timestamp to a file. Why do I need this space ?

Version Info $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga) $ $ echo $0 -ksh I was trying to append date to the file name. The following syntax has worked $ touch HELLO-`date '+%d-%b-%Y'`.txt $ ls -alrt HELL* -rw-r--r-- 1 rlapp oinstall 0 Feb 20... (2 Replies)
Discussion started by: John K
2 Replies

3. UNIX for Dummies Questions & Answers

Appending Date at the end ONLY in first line of file

Hi, My requirement is to append a date in format DDMMYYYYHHMISS at the end of first line of file which is HEADER. I am trying command sed -i '1s/.*/&<date_format>/' <file_name> Where <date_format>=`date +%m%d%Y%H%M%S` I am somehow misisng the right quotes ti get this added in above... (2 Replies)
Discussion started by: sanjaydubey2006
2 Replies

4. UNIX for Dummies Questions & Answers

Appending timestamp problem

Hi, I am trying to insert a timestamp after all the file names in a folder,after the timestamp is created in the filename the file size is becoming zero bytes. please tell me where I am doing it wrong. I have declared the variable in starting of my script. timestamp=`date... (1 Reply)
Discussion started by: shruthidwh
1 Replies

5. Shell Programming and Scripting

appending data to last line of file

A friend contacted me recently with an interesting question. We got something worked out, but I'm curious what answers you all can come up with. Given a shell script (in bash) that processes a bunch of data and appends it to a file, how would you append the date, time, and a filename to the... (6 Replies)
Discussion started by: malcolmpdx
6 Replies

6. Shell Programming and Scripting

Appending a column in one file to the corresponding line in a second

It appears that this has been asked and answered in similar fashions previously, but I am still unsure how to approach this. I have two files containing user information: fileA ttim:/home/ttim:Tiny Tim:632 ppinto:/home/ppinto:Pam Pinto:633 fileB ttim:xkfgjkd*&#^jhdfh... (3 Replies)
Discussion started by: suzannef
3 Replies

7. Shell Programming and Scripting

Appending a line in a file after a particular line

Hello, I have got a C file in which I would like to add an include statement of my own. There are already a few include statements and mine should come right after the last existing one (to be neat). With grep I can get the lines containing the word 'include' and I guess I should feed the... (7 Replies)
Discussion started by: maxvirrozeito
7 Replies

8. Shell Programming and Scripting

Appending the line number and a seperator to each line of a file ?

Hi, I am a newb as far as shell scripting and SED goes so bear with me on this one. I want to basically append to each line in a file a delimiter character and the line's line number e.g Change the file from :- aaaaaa bbbbbb cccccc to:- aaaaaa;1 bbbbbb;2 cccccc;3 I have worked... (4 Replies)
Discussion started by: pjcwhite
4 Replies

9. UNIX for Dummies Questions & Answers

appending timestamp to a file

hi freinds, i need to append timestamp to a file name to make it unique... do we have any command in unix to do please help :confused: (2 Replies)
Discussion started by: madhu_aqua14
2 Replies

10. Shell Programming and Scripting

Appending data at the first and last line of a file

Hi, Am trying to write a shell script which will append a header and a footer to an existing file. Header will contain details like the current date while the footer will contain the no: of records listed in the file. I know we can use the CAT command, but i have no clue abt the syntax to... (4 Replies)
Discussion started by: brainstormer
4 Replies

Featured Tech Videos