How to remove leading and trailing whitespaces?

前端 未结 4 1067
遇见更好的自我
遇见更好的自我 2021-02-07 13:43

I\'m using awk \'{gsub(/^[ \\t]+|[ \\t]+$/,\"\"); print;}\' in.txt > out.txt to remove both leading and trailing whitespaces.

The problem is the output f

4条回答
  •  天涯浪人
    2021-02-07 14:09

    Your files probably have Windows line endings. That means that they end with \r\n, so matching a sequence of tabs and spaces at the end of the line won't work -- awk tries to match all the tabs and spaces that come after the \r. Try running the file through tr -d "\r" before sending it to awk.

提交回复
热议问题