2015年1月15日星期四

convert date string to epoch in awk

convert date string to epoch in awk

In a program I need to convert date string like 2015-01-15 09:23:19 to epoch.

Suppose I have a text file a.txt like this:

2015-01-15 09:23:19
2015-01-15 09:23:30
2015-01-15 09:24:21

At first , I use shell to do it.

awk script1

awk -F"\t" '{ 
    cmd="date -d \""$1"\" +%s";
    cmd|getline epoch;
    print $1;
    close(cmd)
}'  a.txt > epoch.txt

Then, I use the mktime funciton in awk to do it:

awk -F"\t" '{
    a=$(NF-1); 
    split(a, vec, " ")
    split(vec[1], ymd,"-") 
    split(vec[2],hms,":") 
    a=ymd[1]" "ymd[2]" "ymd[3]" "hms[1]" "hms[2]" "hms[3]
    print $3"\t"$4"\t"$13"\t"mktime(a) 
}'  a.txt > epoch.txt

I compared this two methods to a 5 million line file. The first method takes several hours to do it while the second takes only about 1 min! The difference is amazing.

2015年1月7日星期三

svn 使用方法

昨天对一个更新流程进行提测,熟悉了一下svn的使用方法,特此记录一下

首先,在公司的svn仓库中新建一个目录(以new_dir为例)

svn  mkdir http://svn.a.com/svn/new_dir

然后,把新建的目录 new_dir checkout到本地

svn checkout http://svn.a.com/svn/new_dir

最后,将流程中要测试的scripts目录复制到new_dir

svn add scripts

然后,提交

svn ci -m "add scripts directory"

注意!

提交时的message必须满足一定的长度条件,太短的话会提交失败。

如果要查看仓库中是否已经有上面提交的内容,可以用 list命令

svn list http://svn.a.com/svn/new_dir

在整个过程中,我们都可以使用 svn status 命令来查看当前的状态。