Bash Script Regular Expressions…How to find and replace all matches?

后端 未结 4 790
终归单人心
终归单人心 2021-01-17 14:40

I am writing a bash script that reads a file line by line.

The file is a .csv file which contains many dates in the format DD/MM/YYYY but I would like to change the

4条回答
  •  一个人的身影
    2021-01-17 15:03

    Try this using sed:

    line='Today is 10/12/2010 and yesterday was 9/11/2010'
    echo "$line" | sed -r 's#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})#\3-\2-\1#g'
    
    OUTPUT:
    Today is 2010-12-10 and yesterday was 2010-11-9
    

    PS: On mac use sed -E instead of sed -r

提交回复
热议问题