Trim leading and trailing spaces from a string in awk

后端 未结 8 874
离开以前
离开以前 2020-12-01 01:04

I\'m trying to remove leading and trailing space in 2nd column of the below input.txt:

Name, Order  
Trim, working

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 01:50

    just use a regex as a separator:

    ', *' - for leading spaces

    ' *,' - for trailing spaces

    for both leading and trailing:

    awk -F' *,? *' '{print $1","$2}' input.txt
    

提交回复
热议问题