Extract substring using regexp in plain bash

前端 未结 4 1202
清酒与你
清酒与你 2020-11-27 10:52

I\'m trying to extract the time from a string using bash, and I\'m having a hard time figuring it out.

My string is like this:

US/Central - 10:26 PM          


        
4条回答
  •  渐次进展
    2020-11-27 11:23

    Quick 'n dirty, regex-free, low-robustness chop-chop technique

    string="US/Central - 10:26 PM (CST)"
    etime="${string% [AP]M*}"
    etime="${etime#* - }"
    

提交回复
热议问题