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
# 8  
Old 11-24-2011
Try this...
Code:
awk '{match($0,"([0-9-]+)-([0-9]+)",a);cmd="date -d\""a[1]" "a[2]"\" +%s"; cmd|getline x; $1=x}1'  input_file

1320989880 1955 891
1320989940 2270 1049
1320990000 1930 904
1320990060 2030 931
1320990120 1944 900
1320990180 1922 875

Hope this is what you want!
--ahamed

Last edited by ahamed101; 11-24-2011 at 11:26 AM..
# 9  
Old 11-24-2011
Try with perl.

Code:
perl -ne 'use POSIX; /^([0-9]+)-([0-9]+)-([0-9]+)-([0-9]{2})([0-9]{2})(.*)/; print mktime(0, $5, $4, $3, $2 - 1, $1 - 1900)."$6\n";' file

# 10  
Old 11-24-2011
Ok it was just a try.
That's why I asked to see if that command worked.

OK we'll need to do some proper stuff,
do you have perl or C?
try:
man strftime

see if it's available.

---------- Post updated at 04:17 PM ---------- Previous update was at 04:11 PM ----------

macmonster much better
# 11  
Old 11-24-2011
Code:
awk '{split($1,a,"-");match(a[4],"(..)(..)",b);t=a[1]OFS a[2]OFS a[3]OFS b[1]OFS b[2]" 00";$1=mktime(t)}1' 
input_file

--ahamed
Login or Register to Ask a Question

Previous Thread | Next Thread

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
Login or Register to Ask a Question