Printing only the first field in a string

后端 未结 3 649
一整个雨季
一整个雨季 2020-12-05 23:03

I have a date as 12/12/2013 14:32 I want to convert it into only 12/12/2013. The string can be 1/1/2013 12:32 or 1/10/2013 23:41

3条回答
  •  失恋的感觉
    2020-12-05 23:19

    If your date string is stored in a variable, then you don't need to run an external program like cut, awk or sed, because modern shells like bash can perform string manipulation directly which is more efficient.

    For example, in bash:

    $ s="1/10/2013 23:41"
    $ echo "${s% *}"
    1/10/2013
    

提交回复
热议问题