简体   繁体   中英

update csv field with current time stamp value in shell script

I am after a bash script mainly to update a CSV file containing a only row like below:

08/01/2017 2:58,0.32967,0.29304,nan,nan,0.989011,0.671551,12.68,83.1975,11.0937

So the requirement is to update the first column ie timestamp value with the current timestamp value (in the above format) every time when I run the script to change the value.

here is a sed pattern which seems to work for your case:

sed -i "s|^[^,]*|`date '+%d/%m/%Y %H:%M'`|g" <yourfile>

This code will take everything from beginning which is not a coma (and will stop when it encounters one) and will replace it with the output of date linux command with a good formating. the -i options allows you to live edit your file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM