Replacing specific characters in first column of text

前端 未结 2 364
心在旅途
心在旅途 2021-01-13 04:36

I have a text file and I\'m trying to replace a specific character (.) in the first column to another character (-). Every field is delimited by comma. Some of the lines hav

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 05:14

    This might work for you:

    awk -F, -vOFS=, '{for(n=1;n<=3;n++)sub(/\./,"-",$1)}1' file
    abc-def-ghi-qqq.www,123.4561.789,ABC,DEF,GHI
    abc-def-ghq-qqq.www,124.4562.789,ABC,DEF,GHI
    abc-def-ghw-qqq.www,125.4563.789,ABC,DEF,GHI
    abc-def-ghe-qqq.www,126.4564.789,,,
    abc-def-ghr-qqq.www,127.4565.789,,,
    

提交回复
热议问题