Bash script to convert a date and time column to unix timestamp in .csv

前端 未结 3 1028
我在风中等你
我在风中等你 2021-01-05 06:49

I am trying to create a script to convert two columns in a .csv file which are date and time into unix timestamps. So i need to get the date and time column from each row, c

3条回答
  •  执笔经年
    2021-01-05 07:16

    this should do the job:

     awk  'BEGIN{FS=OFS=", "}{t=$1" "$2; "date -d \""t"\"  +%s"|getline d; print $1,$2,d}' yourCSV.csv
    

    note

    you didn't give any example. and you mentioned csv, so I assume that the column separator in your file should be "comma".

    test

    kent$  echo "2011/11/25, 10:00:00"|awk  'BEGIN{FS=OFS=", "}{t=$1" "$2; "date -d \""t"\"  +%s"|getline d; print $1,$2,d}'
    2011/11/25, 10:00:00, 1322211600
    

提交回复
热议问题