How to remove trailing whitespaces with sed?

后端 未结 10 906
我在风中等你
我在风中等你 2020-11-28 21:49

I have a simple shell script that removes trailing whitespace from a file. Is there any way to make this script more compact (without creating a temporary file)?

<         


        
10条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 22:20

    To only strip whitespaces (in my case spaces and tabs) from lines with at least one non-whitespace character (this way empty indented lines are not touched):

    sed -i -r 's/([^ \t]+)[ \t]+$/\1/' "$file"
    

提交回复
热议问题